From cebf1fea4a6802b8999469f647f52171e87d02b6 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Wed, 28 Dec 2016 15:27:57 +0100 Subject: Add redirects policy to QNetworkAccessManager This patch makes it possible to enable/disable redirects on QNAM level (before it was per-request only). This policy would be applied to all subsequent requests* created by QNAM. The policies we support at the moment: a. Manual - that's what we always had - it's up to a user to handle redirects. b. NoLessSafeRedirectsPolicy - we allow http->http, http->https and https->https redirects, but no protocol 'downgrade' (no https->http redirects). c. SameOriginPolicy - we check that protocol/host/port are the same. Updated tst_qnetworkreply. *We previously were enabling redirect for each request, by setting FollowRedirectsAttribute on QNetworkRequest object. For backward compatibility this attribute has a higher priority (if set) than QNAM's policy (and it will work as NoLessSafeRedirectsPolicy). [ChangeLog][QtNetwork] Added redirects policy to QNAM Task-number: QTPM-239 Task-number: QTPM-237 Change-Id: I493d1728254b71b61b5504937e8e01dca5953527 Reviewed-by: Timur Pocheptsov --- src/network/access/qnetworkrequest.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'src/network/access/qnetworkrequest.cpp') diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp index bc2507ca51c..abc924d0e23 100644 --- a/src/network/access/qnetworkrequest.cpp +++ b/src/network/access/qnetworkrequest.cpp @@ -289,6 +289,12 @@ QT_BEGIN_NAMESPACE marked to be decompressed automatically. (This value was introduced in 5.9.) + \value RedirectsPolicyAttribute + Requests only, type: QMetaType::Int, should be one of the + QNetworkRequest::RedirectsPolicy values (default: ManualRedirectsPolicy). + This attribute obsoletes FollowRedirectsAttribute. + (This value was introduced in 5.9.) + \value User Special type. Additional information can be passed in QVariants with types ranging from User to UserMax. The default @@ -336,6 +342,26 @@ QT_BEGIN_NAMESPACE \value Manual indicates behaviour has been manually overridden. */ +/*! + \enum QNetworkRequest::RedirectsPolicy + \since 5.9 + + Indicates whether the Network Access API should automatically follow a + HTTP redirect response or not. + + \value ManualRedirectsPolicy Default value: not following any redirects. + + \value NoLessSafeRedirectsPolicy Only "http"->"http", "http" -> "https" + or "https" -> "https" redirects are allowed. + Equivalent to setting the old FollowRedirectsAttribute + to true + + \value SameOriginRedirectsPolicy Require the same protocol, host and port. + Note, http://example.com and http://example.com:80 + will fail with this policy (implicit/explicit ports + are considered to be a mismatch). +*/ + class QNetworkRequestPrivate: public QSharedData, public QNetworkHeadersPrivate { public: -- cgit v1.2.3