diff options
author | Mandeep Sandhu <mandeepsandhu.chd@gmail.com> | 2014-03-17 19:21:25 +0530 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@theqtcompany.com> | 2015-03-09 08:32:14 +0000 |
commit | d815de8c26ccee33713e37a0fec2982755dcfe1f (patch) | |
tree | 9bfae5a77f94368c139e5290399a9f7ec6471367 /src/network/access/qnetworkreply.cpp | |
parent | f7118e7f1b495fc0a0b8d83dff1a207dfddb09aa (diff) |
QNetworkAccessManager: Support HTTP redirection
This commit adds support for following HTTP redirect responses on a per
request basis.
This behavior is disabled by default. It can be switched on by
setting the QNetworkRequest::FollowRedirectAttribute to true.
2 new error codes have been added to QNetworkReply:
* TooManyRedirectsError: Set when the number of redirects exceed a
given value set by the user (defaults to 50 if not set)
* UnsecureRedirectError: Set when we are redirecting from a 'https'
to 'http' protocol.
Test cases for the following scenarios:
* Single HTTP redirect using local test server
* Changing max-redirects
* Testing all redirect related error scenarios
The next commit will extend this feature at a QNAM level.
Task-number: QTBUG-8232
Change-Id: If9e28ad12bad08bcdc5bc511b1cd59dc9d8150f0
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@theqtcompany.com>
Diffstat (limited to 'src/network/access/qnetworkreply.cpp')
-rw-r--r-- | src/network/access/qnetworkreply.cpp | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/network/access/qnetworkreply.cpp b/src/network/access/qnetworkreply.cpp index 3e77e1b874..26f7034c09 100644 --- a/src/network/access/qnetworkreply.cpp +++ b/src/network/access/qnetworkreply.cpp @@ -132,6 +132,14 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() \value BackgroundRequestNotAllowedError the background request is not currently allowed due to platform policy. + \value TooManyRedirectsError while following redirects, the maximum + limit was reached. The limit is by default set to 50 or as set by + QNetworkRequest::setMaxRedirectsAllowed(). + + \value InsecureRedirectError while following redirects, the network + access API detected a redirect from a encrypted protocol (https) to an + unencrypted one (http). + \value ProxyConnectionRefusedError the connection to the proxy server was refused (the proxy server is not accepting requests) @@ -276,6 +284,19 @@ QNetworkReplyPrivate::QNetworkReplyPrivate() */ /*! + \fn void QNetworkReply::redirected(const QUrl &url) + \since 5.6 + + This signal is emitted if the QNetworkRequest::FollowRedirectsAttribute was + set in the request and the server responded with a 3xx status (specifically + 301, 302, 303, 305 or 307 status code) with a valid url in the location + header, indicating a HTTP redirect. The \a url parameter contains the new + redirect url as returned by the server in the location header. + + \sa QNetworkRequest::FollowRedirectsAttribute +*/ + +/*! \fn void QNetworkReply::metaDataChanged() \omit FIXME: Update name? \endomit @@ -498,7 +519,7 @@ QNetworkAccessManager *QNetworkReply::manager() const */ QNetworkRequest QNetworkReply::request() const { - return d_func()->request; + return d_func()->originalRequest; } /*! @@ -549,9 +570,12 @@ bool QNetworkReply::isRunning() const /*! Returns the URL of the content downloaded or uploaded. Note that - the URL may be different from that of the original request. + the URL may be different from that of the original request. If the + QNetworkRequest::FollowRedirectsAttribute was set in the request, then this + function returns the current url that the network API is accessing, i.e the + url emitted in the QNetworkReply::redirected signal. - \sa request(), setUrl(), QNetworkRequest::url() + \sa request(), setUrl(), QNetworkRequest::url(), redirected() */ QUrl QNetworkReply::url() const { @@ -794,7 +818,7 @@ void QNetworkReply::setOperation(QNetworkAccessManager::Operation operation) void QNetworkReply::setRequest(const QNetworkRequest &request) { Q_D(QNetworkReply); - d->request = request; + d->originalRequest = request; } /*! |