From 6f1d5d480b3d6c96e3324f8f3792dd71071224bb Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Thu, 19 Feb 2015 10:14:20 +0100 Subject: [PATCH] HttpRequest: implement POST>GET conversion on redirects 302 and 303 redirects must convert POST requests to GET (and remove the POST data). Fixes the following problems (at least): * Login to github going to the "unicorn!" page * Gmail failing to load and staying at the loaderbar page --- src/kits/network/libnetapi/HttpRequest.cpp | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/kits/network/libnetapi/HttpRequest.cpp b/src/kits/network/libnetapi/HttpRequest.cpp index 1da64c2ecc..95d213fc3f 100644 --- a/src/kits/network/libnetapi/HttpRequest.cpp +++ b/src/kits/network/libnetapi/HttpRequest.cpp @@ -383,20 +383,33 @@ BHttpRequest::_ProtocolLoop() break; case B_HTTP_STATUS_CLASS_REDIRECTION: + { // Redirection has been explicitly disabled if (!fOptFollowLocation) break; - // TODO: Some browsers seems to translate POST requests to - // GET when following a 302 redirection. 303 should do the same, - // but NOT 307. - if (fResult.StatusCode() == B_HTTP_STATUS_MOVED_PERMANENTLY - || fResult.StatusCode() == B_HTTP_STATUS_TEMPORARY_REDIRECT - || fResult.StatusCode() == B_HTTP_STATUS_FOUND) { + int code = fResult.StatusCode(); + if (code == B_HTTP_STATUS_MOVED_PERMANENTLY + || code == B_HTTP_STATUS_FOUND + || code == B_HTTP_STATUS_SEE_OTHER + || code == B_HTTP_STATUS_TEMPORARY_REDIRECT) { BString locationUrl = fHeaders["Location"]; fUrl = BUrl(fUrl, locationUrl); + // 302 and 303 redirections also convert POST requests to GET + // (and remove the posted form data) + if ((code == B_HTTP_STATUS_FOUND + || code == B_HTTP_STATUS_SEE_OTHER) + && fRequestMethod == B_HTTP_POST) { + SetMethod(B_HTTP_GET); + delete fOptPostFields; + fOptPostFields = NULL; + delete fOptInputData; + fOptInputData = NULL; + fOptInputDataSize = 0; + } + if (--maxRedirs > 0) { newRequest = true; @@ -412,6 +425,7 @@ BHttpRequest::_ProtocolLoop() } } break; + } case B_HTTP_STATUS_CLASS_CLIENT_ERROR: if (fResult.StatusCode() == B_HTTP_STATUS_UNAUTHORIZED) {