From d815de8c26ccee33713e37a0fec2982755dcfe1f Mon Sep 17 00:00:00 2001 From: Mandeep Sandhu Date: Mon, 17 Mar 2014 19:21:25 +0530 Subject: 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 --- src/network/access/qhttpnetworkrequest.cpp | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'src/network/access/qhttpnetworkrequest.cpp') diff --git a/src/network/access/qhttpnetworkrequest.cpp b/src/network/access/qhttpnetworkrequest.cpp index ea1cd3d591..64172fc4fd 100644 --- a/src/network/access/qhttpnetworkrequest.cpp +++ b/src/network/access/qhttpnetworkrequest.cpp @@ -42,7 +42,7 @@ QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(QHttpNetworkRequest::Oper QHttpNetworkRequest::Priority pri, const QUrl &newUrl) : QHttpNetworkHeaderPrivate(newUrl), operation(op), priority(pri), uploadByteDevice(0), autoDecompress(false), pipeliningAllowed(false), spdyAllowed(false), - withCredentials(true), preConnect(false) + withCredentials(true), preConnect(false), followRedirect(false), redirectCount(0) { } @@ -59,6 +59,8 @@ QHttpNetworkRequestPrivate::QHttpNetworkRequestPrivate(const QHttpNetworkRequest withCredentials = other.withCredentials; ssl = other.ssl; preConnect = other.preConnect; + followRedirect = other.followRedirect; + redirectCount = other.redirectCount; } QHttpNetworkRequestPrivate::~QHttpNetworkRequestPrivate() @@ -217,6 +219,26 @@ void QHttpNetworkRequest::setPreConnect(bool preConnect) d->preConnect = preConnect; } +bool QHttpNetworkRequest::isFollowRedirects() const +{ + return d->followRedirect; +} + +void QHttpNetworkRequest::setFollowRedirects(bool followRedirect) +{ + d->followRedirect = followRedirect; +} + +int QHttpNetworkRequest::redirectCount() const +{ + return d->redirectCount; +} + +void QHttpNetworkRequest::setRedirectCount(int count) +{ + d->redirectCount = count; +} + qint64 QHttpNetworkRequest::contentLength() const { return d->contentLength(); -- cgit v1.2.3