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
This commit is contained in:
Adrien Destugues
2015-02-19 10:19:04 +01:00
parent efca2820cc
commit 6f1d5d480b
+20 -6
View File
@@ -383,20 +383,33 @@ BHttpRequest::_ProtocolLoop()
break; break;
case B_HTTP_STATUS_CLASS_REDIRECTION: case B_HTTP_STATUS_CLASS_REDIRECTION:
{
// Redirection has been explicitly disabled // Redirection has been explicitly disabled
if (!fOptFollowLocation) if (!fOptFollowLocation)
break; break;
// TODO: Some browsers seems to translate POST requests to int code = fResult.StatusCode();
// GET when following a 302 redirection. 303 should do the same, if (code == B_HTTP_STATUS_MOVED_PERMANENTLY
// but NOT 307. || code == B_HTTP_STATUS_FOUND
if (fResult.StatusCode() == B_HTTP_STATUS_MOVED_PERMANENTLY || code == B_HTTP_STATUS_SEE_OTHER
|| fResult.StatusCode() == B_HTTP_STATUS_TEMPORARY_REDIRECT || code == B_HTTP_STATUS_TEMPORARY_REDIRECT) {
|| fResult.StatusCode() == B_HTTP_STATUS_FOUND) {
BString locationUrl = fHeaders["Location"]; BString locationUrl = fHeaders["Location"];
fUrl = BUrl(fUrl, locationUrl); 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) { if (--maxRedirs > 0) {
newRequest = true; newRequest = true;
@@ -412,6 +425,7 @@ BHttpRequest::_ProtocolLoop()
} }
} }
break; break;
}
case B_HTTP_STATUS_CLASS_CLIENT_ERROR: case B_HTTP_STATUS_CLASS_CLIENT_ERROR:
if (fResult.StatusCode() == B_HTTP_STATUS_UNAUTHORIZED) { if (fResult.StatusCode() == B_HTTP_STATUS_UNAUTHORIZED) {