diff --git a/libcef/browser/net_service/proxy_url_loader_factory.cc b/libcef/browser/net_service/proxy_url_loader_factory.cc index 3a16e4604..21f60adab 100644 --- a/libcef/browser/net_service/proxy_url_loader_factory.cc +++ b/libcef/browser/net_service/proxy_url_loader_factory.cc @@ -839,15 +839,26 @@ void InterceptedRequest::ContinueToBeforeRedirect( request_.url = redirect_info.new_url; } + // If request_ changes from POST to GET, strip POST headers. + const bool post_to_get = + request_.method == "POST" && + redirect_info.new_method == net::HttpRequestHeaders::kGetMethod; + request_.method = redirect_info.new_method; request_.site_for_cookies = redirect_info.new_site_for_cookies; request_.referrer = GURL(redirect_info.new_referrer); request_.referrer_policy = redirect_info.new_referrer_policy; // The request method can be changed to "GET". In this case we need to - // reset the request body manually. - if (request_.method == net::HttpRequestHeaders::kGetMethod) + // reset the request body manually, and strip the POST headers. + if (request_.method == net::HttpRequestHeaders::kGetMethod) { request_.request_body = nullptr; + + if (post_to_get) { + request_.headers.RemoveHeader(net::HttpRequestHeaders::kContentLength); + request_.headers.RemoveHeader(net::HttpRequestHeaders::kContentType); + } + } } void InterceptedRequest::ContinueToResponseStarted(int error_code) { diff --git a/tests/ceftests/urlrequest_unittest.cc b/tests/ceftests/urlrequest_unittest.cc index 97d3b3c2b..508f70e77 100644 --- a/tests/ceftests/urlrequest_unittest.cc +++ b/tests/ceftests/urlrequest_unittest.cc @@ -1424,6 +1424,18 @@ class RequestServerHandler : public CefServerHandler { CefRefPtr request, CefRefPtr redirect_request, CefRefPtr redirect_response) { + if (redirect_response->GetStatus() == 302) { + // Simulate wrong copying of POST-specific headers Content-Type and + // Content-Length. A 302 redirect should end up in a GET request and + // these headers should not propagate from a 302 POST-to-GET redirect. + CefResponse::HeaderMap redirectHeaderMap; + redirect_response->GetHeaderMap(redirectHeaderMap); + redirectHeaderMap.insert( + std::make_pair("content-type", "application/x-www-form-urlencoded")); + redirectHeaderMap.insert(std::make_pair("content-length", "0")); + redirect_response->SetHeaderMap(redirectHeaderMap); + } + // Verify that the request was sent correctly. TestRequestEqual(redirect_request, request, true);