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 453b6d94d42a223f5d8d8d622b4c68970b126020..0a810d4b506412b8ea1dd1fcef79859604fd8965 100644 |
| --- a/net/http/proxy_client_socket.cc |
| +++ b/net/http/proxy_client_socket.cc |
| @@ -4,6 +4,8 @@ |
| #include "net/http/proxy_client_socket.h" |
| +#include <unordered_set> |
| + |
| #include "base/metrics/histogram_macros.h" |
| #include "base/strings/stringprintf.h" |
| #include "net/base/host_port_pair.h" |
| @@ -16,20 +18,6 @@ |
| namespace net { |
| -namespace { |
| - |
| -void CopyHeaderValues(scoped_refptr<HttpResponseHeaders> source, |
| - scoped_refptr<HttpResponseHeaders> dest, |
| - const std::string& header_name) { |
| - size_t iter = 0; |
| - std::string header_value; |
| - |
| - while (source->EnumerateHeader(&iter, header_name, &header_value)) |
| - dest->AddHeader(header_name + ": " + header_value); |
| -} |
| - |
| -} // namespace |
| - |
| // static |
| void ProxyClientSocket::BuildTunnelRequest( |
| const HostPortPair& endpoint, |
| @@ -87,27 +75,40 @@ void ProxyClientSocket::LogBlockedTunnelResponse(int http_status_code, |
| 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, arraysize(kHeaders))); |
| + response->headers->ReplaceStatusLine( |
| + "HTTP/1.1 407 Proxy Authentication Required"); |
| // Copy status line and all hop-by-hop headers to preserve keep-alive |
| // behavior. |
| - new_headers->ReplaceStatusLine(old_headers->GetStatusLine()); |
| - CopyHeaderValues(old_headers, new_headers, "connection"); |
| - CopyHeaderValues(old_headers, new_headers, "proxy-connection"); |
| - CopyHeaderValues(old_headers, new_headers, "keep-alive"); |
| - CopyHeaderValues(old_headers, new_headers, "trailer"); |
| - CopyHeaderValues(old_headers, new_headers, "transfer-encoding"); |
| - CopyHeaderValues(old_headers, new_headers, "upgrade"); |
| + // Note that these must be lower case. |
| + const char* kHeadersToKeep[] = { |
| + "connection", "proxy-connection", "keep-alive", "trailer", |
| + "transfer-encoding", "upgrade", |
| + |
| + "content-length", |
| + |
| + "proxy-authenticate", |
| + }; |
| - CopyHeaderValues(old_headers, new_headers, "content-length"); |
| + size_t iter = 0; |
| + std::string header_name; |
| + std::string header_value; |
| + std::unordered_set<std::string> headers_to_remove; |
| + while (response->headers->EnumerateHeaderLines(&iter, &header_name, |
| + &header_value)) { |
|
mmenke
2017/01/19 18:51:55
I went with this approach instead of adding a "Rem
|
| + bool remove = true; |
| + for (const char* header : kHeadersToKeep) { |
| + if (header == header_name) { |
| + remove = false; |
| + break; |
| + } |
| + } |
| + if (remove) |
| + headers_to_remove.insert(header_name); |
| + } |
| - CopyHeaderValues(old_headers, new_headers, "proxy-authenticate"); |
| + response->headers->RemoveHeaders(headers_to_remove); |
| - response->headers = new_headers; |
| return true; |
| } |