OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/proxy_client_socket.h" | 5 #include "net/http/proxy_client_socket.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "net/base/host_port_pair.h" | 9 #include "net/base/host_port_pair.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 std::string header_value; | 26 std::string header_value; |
27 | 27 |
28 while (source->EnumerateHeader(&iter, header_name, &header_value)) | 28 while (source->EnumerateHeader(&iter, header_name, &header_value)) |
29 dest->AddHeader(header_name + ": " + header_value); | 29 dest->AddHeader(header_name + ": " + header_value); |
30 } | 30 } |
31 | 31 |
32 } // namespace | 32 } // namespace |
33 | 33 |
34 // static | 34 // static |
35 void ProxyClientSocket::BuildTunnelRequest( | 35 void ProxyClientSocket::BuildTunnelRequest( |
36 const HttpRequestInfo& request_info, | 36 const HostPortPair& endpoint, |
37 const HttpRequestHeaders& auth_headers, | 37 const HttpRequestHeaders& auth_headers, |
38 const HostPortPair& endpoint, | 38 const std::string& user_agent, |
39 std::string* request_line, | 39 std::string* request_line, |
40 HttpRequestHeaders* request_headers) { | 40 HttpRequestHeaders* request_headers) { |
41 // RFC 2616 Section 9 says the Host request-header field MUST accompany all | 41 // RFC 2616 Section 9 says the Host request-header field MUST accompany all |
42 // HTTP/1.1 requests. Add "Proxy-Connection: keep-alive" for compat with | 42 // HTTP/1.1 requests. Add "Proxy-Connection: keep-alive" for compat with |
43 // HTTP/1.0 proxies such as Squid (required for NTLM authentication). | 43 // HTTP/1.0 proxies such as Squid (required for NTLM authentication). |
44 *request_line = base::StringPrintf( | 44 std::string host_and_port = endpoint.ToString(); |
45 "CONNECT %s HTTP/1.1\r\n", endpoint.ToString().c_str()); | 45 *request_line = |
46 request_headers->SetHeader(HttpRequestHeaders::kHost, | 46 base::StringPrintf("CONNECT %s HTTP/1.1\r\n", host_and_port.c_str()); |
47 GetHostAndOptionalPort(request_info.url)); | 47 request_headers->SetHeader(HttpRequestHeaders::kHost, endpoint.port() == 443 |
| 48 ? endpoint.host() |
| 49 : host_and_port); |
48 request_headers->SetHeader(HttpRequestHeaders::kProxyConnection, | 50 request_headers->SetHeader(HttpRequestHeaders::kProxyConnection, |
49 "keep-alive"); | 51 "keep-alive"); |
50 | 52 if (!user_agent.empty()) |
51 std::string user_agent; | |
52 if (request_info.extra_headers.GetHeader(HttpRequestHeaders::kUserAgent, | |
53 &user_agent)) | |
54 request_headers->SetHeader(HttpRequestHeaders::kUserAgent, user_agent); | 53 request_headers->SetHeader(HttpRequestHeaders::kUserAgent, user_agent); |
55 | 54 |
56 request_headers->MergeFrom(auth_headers); | 55 request_headers->MergeFrom(auth_headers); |
57 } | 56 } |
58 | 57 |
59 // static | 58 // static |
60 int ProxyClientSocket::HandleProxyAuthChallenge(HttpAuthController* auth, | 59 int ProxyClientSocket::HandleProxyAuthChallenge(HttpAuthController* auth, |
61 HttpResponseInfo* response, | 60 HttpResponseInfo* response, |
62 const BoundNetLog& net_log) { | 61 const BoundNetLog& net_log) { |
63 DCHECK(response->headers.get()); | 62 DCHECK(response->headers.get()); |
64 int rv = auth->HandleAuthChallenge(response->headers, false, true, net_log); | 63 int rv = auth->HandleAuthChallenge(response->headers, false, true, net_log); |
65 response->auth_challenge = auth->auth_info(); | 64 response->auth_challenge = auth->auth_info(); |
66 if (rv == OK) | 65 if (rv == OK) |
67 return ERR_PROXY_AUTH_REQUESTED; | 66 return ERR_PROXY_AUTH_REQUESTED; |
68 return rv; | 67 return rv; |
69 } | 68 } |
70 | 69 |
71 // static | 70 // static |
72 void ProxyClientSocket::LogBlockedTunnelResponse(int http_status_code, | 71 void ProxyClientSocket::LogBlockedTunnelResponse(int http_status_code, |
73 const GURL& url, | |
74 bool is_https_proxy) { | 72 bool is_https_proxy) { |
75 if (is_https_proxy) { | 73 if (is_https_proxy) { |
76 UMA_HISTOGRAM_CUSTOM_ENUMERATION( | 74 UMA_HISTOGRAM_CUSTOM_ENUMERATION( |
77 "Net.BlockedTunnelResponse.HttpsProxy", | 75 "Net.BlockedTunnelResponse.HttpsProxy", |
78 HttpUtil::MapStatusCodeForHistogram(http_status_code), | 76 HttpUtil::MapStatusCodeForHistogram(http_status_code), |
79 HttpUtil::GetStatusCodesForHistogram()); | 77 HttpUtil::GetStatusCodesForHistogram()); |
80 } else { | 78 } else { |
81 UMA_HISTOGRAM_CUSTOM_ENUMERATION( | 79 UMA_HISTOGRAM_CUSTOM_ENUMERATION( |
82 "Net.BlockedTunnelResponse.HttpProxy", | 80 "Net.BlockedTunnelResponse.HttpProxy", |
83 HttpUtil::MapStatusCodeForHistogram(http_status_code), | 81 HttpUtil::MapStatusCodeForHistogram(http_status_code), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 location.c_str()); | 129 location.c_str()); |
132 std::string raw_headers = | 130 std::string raw_headers = |
133 HttpUtil::AssembleRawHeaders(fake_response_headers.data(), | 131 HttpUtil::AssembleRawHeaders(fake_response_headers.data(), |
134 fake_response_headers.length()); | 132 fake_response_headers.length()); |
135 response->headers = new HttpResponseHeaders(raw_headers); | 133 response->headers = new HttpResponseHeaders(raw_headers); |
136 | 134 |
137 return true; | 135 return true; |
138 } | 136 } |
139 | 137 |
140 } // namespace net | 138 } // namespace net |
OLD | NEW |