Set the correct response status on internal redirects

This commit is contained in:
Marshall Greenblatt 2017-10-26 13:34:17 -04:00
parent 8b4980b4ca
commit 9334a09176
2 changed files with 17 additions and 8 deletions

View File

@ -286,14 +286,14 @@ bool CefResourceRequestJob::IsRedirectResponse(GURL* location,
int* http_status_code) { int* http_status_code) {
CEF_REQUIRE_IOT(); CEF_REQUIRE_IOT();
bool redirect = false;
if (redirect_url_.is_valid()) { if (redirect_url_.is_valid()) {
// Redirect to the new URL. // Redirect to the new URL.
*http_status_code = 303; *http_status_code = 303;
location->Swap(&redirect_url_); location->Swap(&redirect_url_);
return true; redirect = true;
} } else if (response_.get()) {
if (response_.get()) {
// Check for HTTP 302 or HTTP 303 redirect. // Check for HTTP 302 or HTTP 303 redirect.
int status = response_->GetStatus(); int status = response_->GetStatus();
if (status == 302 || status == 303) { if (status == 302 || status == 303) {
@ -304,12 +304,20 @@ bool CefResourceRequestJob::IsRedirectResponse(GURL* location,
GURL new_url = GURL(std::string(iter->second)); GURL new_url = GURL(std::string(iter->second));
*http_status_code = status; *http_status_code = status;
location->Swap(&new_url); location->Swap(&new_url);
return true; redirect = true;
} }
} }
} }
return false; if (redirect) {
// Set the correct response status. This avoids a DCHECK in
// RedirectInfo::ComputeRedirectInfo.
request_->response_headers()->ReplaceStatusLine(
*http_status_code == 302 ? "HTTP/1.1 302 Found"
: "HTTP/1.1 303 See Other");
}
return redirect;
} }
bool CefResourceRequestJob::GetMimeType(std::string* mime_type) const { bool CefResourceRequestJob::GetMimeType(std::string* mime_type) const {

View File

@ -939,8 +939,9 @@ class RedirectTestHandler : public TestHandler {
// Called due to the nav3 redirect response. // Called due to the nav3 redirect response.
got_nav3_redirect_.yes(); got_nav3_redirect_.yes();
EXPECT_EQ(200, response->GetStatus()); EXPECT_EQ(303, response->GetStatus());
EXPECT_TRUE(response->GetStatusText().empty()); EXPECT_STREQ("See Other",
response->GetStatusText().ToString().c_str());
EXPECT_STREQ("text/html", response->GetMimeType().ToString().c_str()); EXPECT_STREQ("text/html", response->GetMimeType().ToString().c_str());
} else { } else {
got_invalid_redirect_.yes(); got_invalid_redirect_.yes();