Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(499)

Unified Diff: net/http/proxy_client_socket.cc

Issue 2643023003: Speed up sanitizing headers received from HTTP proxies. (Closed)
Patch Set: Fix Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_response_headers_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1cfa0c3a194a70c7d716083e46c427a293f7dcc6 100644
--- a/net/http/proxy_client_socket.cc
+++ b/net/http/proxy_client_socket.cc
@@ -4,7 +4,10 @@
#include "net/http/proxy_client_socket.h"
+#include <unordered_set>
+
#include "base/metrics/histogram_macros.h"
+#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "net/base/host_port_pair.h"
#include "net/base/net_errors.h"
@@ -16,20 +19,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 +76,38 @@ 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)));
-
// 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");
+ const char* kHeadersToKeep[] = {
+ "connection", "proxy-connection", "keep-alive", "trailer",
+ "transfer-encoding", "upgrade",
+
+ "content-length",
+
+ "proxy-authenticate",
+ };
- CopyHeaderValues(old_headers, new_headers, "content-length");
+ // Create a list of all present header not in |kHeadersToKeep|, and then
+ // remove them.
+ 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)) {
+ bool remove = true;
+ for (const char* header : kHeadersToKeep) {
Julia Tuttle 2017/01/19 22:26:40 Might be faster to just unconditionally remove the
mmenke 2017/01/23 17:28:14 The problem with that is the same reason adding he
+ if (base::EqualsCaseInsensitiveASCII(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;
}
« no previous file with comments | « net/http/http_response_headers_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698