Chromium Code Reviews| Index: net/http/proxy_client_socket.cc |
| diff --git a/net/http/proxy_client_socket.cc b/net/http/proxy_client_socket.cc |
| index dcfae037ce721c92bd95dfa3aeded77bd2f6bf62..580c2112dd1fff03488e372336bffb7521dd8e92 100644 |
| --- a/net/http/proxy_client_socket.cc |
| +++ b/net/http/proxy_client_socket.cc |
| @@ -17,6 +17,20 @@ |
| namespace net { |
| +namespace { |
| + |
| +void CopyHeaderValues(scoped_refptr<HttpResponseHeaders> source, |
| + scoped_refptr<HttpResponseHeaders> dest, |
| + const std::string& header_name) { |
| + void* iter = NULL; |
| + std::string header_value; |
| + |
| + while (source->EnumerateHeader(&iter, header_name, &header_value)) |
| + dest->AddHeader(header_name + ": " + header_value); |
| +} |
| + |
| +} // namespace |
| + |
| // static |
| void ProxyClientSocket::BuildTunnelRequest( |
| const HttpRequestInfo& request_info, |
| @@ -72,22 +86,39 @@ void ProxyClientSocket::LogBlockedTunnelResponse(int http_status_code, |
| } |
| // static |
| -bool ProxyClientSocket::SanitizeProxyRedirect(HttpResponseInfo* response, |
| - const GURL& url) { |
| +bool ProxyClientSocket::SanitizeProxyAuth(HttpResponseInfo* response) { |
| + DCHECK(response && response->headers.get()); |
| + |
| + scoped_refptr<HttpResponseHeaders> old_headers = response->headers; |
| + |
| + const char* kHeaders = "HTTP/1.1 407 Proxy Authentication Required\n\n"; |
| + scoped_refptr<HttpResponseHeaders> new_headers = new HttpResponseHeaders( |
| + HttpUtil::AssembleRawHeaders(kHeaders, strlen(kHeaders))); |
| + |
| + new_headers->ReplaceStatusLine(old_headers->GetStatusLine()); |
| + CopyHeaderValues(old_headers, new_headers, "Connection"); |
|
Ryan Hamilton
2014/12/19 21:26:59
I sure would have thought that you'd need both Con
Ryan Sleevi
2014/12/19 21:30:25
Agreed. This is why I have trouble understanding h
Deprecated (see juliatuttle)
2014/12/19 21:50:46
Content-Length is read by the HttpStreamParser. We
Ryan Hamilton
2014/12/19 21:53:45
Ah, I missed the last part. Ok, makes sense.
|
| + CopyHeaderValues(old_headers, new_headers, "Proxy-Authenticate"); |
| + |
| + response->headers = new_headers; |
| + return true; |
| +} |
| + |
| +// static |
| +bool ProxyClientSocket::SanitizeProxyRedirect(HttpResponseInfo* response) { |
| DCHECK(response && response->headers.get()); |
| std::string location; |
| if (!response->headers->IsRedirect(&location)) |
| return false; |
| - // Return minimal headers; set "Content-length: 0" to ignore response body. |
| - std::string fake_response_headers = |
| - base::StringPrintf("HTTP/1.0 302 Found\n" |
| - "Location: %s\n" |
| - "Content-length: 0\n" |
| - "Connection: close\n" |
| - "\n", |
| - location.c_str()); |
| + // Return minimal headers; set "Content-Length: 0" to ignore response body. |
| + std::string fake_response_headers = base::StringPrintf( |
| + "HTTP/1.0 302 Found\n" |
| + "Location: %s\n" |
| + "Content-Length: 0\n" |
| + "Connection: close\n" |
| + "\n", |
| + location.c_str()); |
| std::string raw_headers = |
| HttpUtil::AssembleRawHeaders(fake_response_headers.data(), |
| fake_response_headers.length()); |