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/qhttpnetworkreply.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/qhttpnetworkreply.cpp')
-rw-r--r-- | src/network/access/qhttpnetworkreply.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp index 2063ca6bd0..172d4dab5b 100644 --- a/src/network/access/qhttpnetworkreply.cpp +++ b/src/network/access/qhttpnetworkreply.cpp @@ -78,6 +78,23 @@ void QHttpNetworkReply::setUrl(const QUrl &url) d->url = url; } +QUrl QHttpNetworkReply::redirectUrl() const +{ + return d_func()->redirectUrl; +} + +void QHttpNetworkReply::setRedirectUrl(const QUrl &url) +{ + Q_D(QHttpNetworkReply); + d->redirectUrl = url; +} + +bool QHttpNetworkReply::isHttpRedirect(int statusCode) +{ + return (statusCode == 301 || statusCode == 302 || statusCode == 303 + || statusCode == 305 || statusCode == 307); +} + qint64 QHttpNetworkReply::contentLength() const { return d_func()->contentLength(); @@ -267,6 +284,11 @@ void QHttpNetworkReply::setSpdyWasUsed(bool spdy) d_func()->spdyUsed = spdy; } +bool QHttpNetworkReply::isRedirecting() const +{ + return d_func()->isRedirecting(); +} + QHttpNetworkConnection* QHttpNetworkReply::connection() { return d_func()->connection; @@ -910,6 +932,14 @@ qint64 QHttpNetworkReplyPrivate::getChunkSize(QAbstractSocket *socket, qint64 *c return bytes; } +bool QHttpNetworkReplyPrivate::isRedirecting() const +{ + // We're in the process of redirecting - if the HTTP status code says so and + // followRedirect is switched on + return (QHttpNetworkReply::isHttpRedirect(statusCode) + && request.isFollowRedirects()); +} + bool QHttpNetworkReplyPrivate::shouldEmitSignals() { // for 401 & 407 don't emit the data signals. Content along with these |