| 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/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "googleurl/src/gurl.h" | 9 #include "googleurl/src/gurl.h" |
| 10 #include "net/base/host_port_pair.h" | 10 #include "net/base/host_port_pair.h" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 &user_agent)) | 39 &user_agent)) |
| 40 request_headers->SetHeader(HttpRequestHeaders::kUserAgent, user_agent); | 40 request_headers->SetHeader(HttpRequestHeaders::kUserAgent, user_agent); |
| 41 | 41 |
| 42 request_headers->MergeFrom(auth_headers); | 42 request_headers->MergeFrom(auth_headers); |
| 43 } | 43 } |
| 44 | 44 |
| 45 // static | 45 // static |
| 46 int ProxyClientSocket::HandleProxyAuthChallenge(HttpAuthController* auth, | 46 int ProxyClientSocket::HandleProxyAuthChallenge(HttpAuthController* auth, |
| 47 HttpResponseInfo* response, | 47 HttpResponseInfo* response, |
| 48 const BoundNetLog& net_log) { | 48 const BoundNetLog& net_log) { |
| 49 DCHECK(response->headers); | 49 DCHECK(response->headers.get()); |
| 50 int rv = auth->HandleAuthChallenge(response->headers, false, true, net_log); | 50 int rv = auth->HandleAuthChallenge(response->headers, false, true, net_log); |
| 51 response->auth_challenge = auth->auth_info(); | 51 response->auth_challenge = auth->auth_info(); |
| 52 if (rv == OK) | 52 if (rv == OK) |
| 53 return ERR_PROXY_AUTH_REQUESTED; | 53 return ERR_PROXY_AUTH_REQUESTED; |
| 54 return rv; | 54 return rv; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // static | 57 // static |
| 58 void ProxyClientSocket::LogBlockedTunnelResponse(int http_status_code, | 58 void ProxyClientSocket::LogBlockedTunnelResponse(int http_status_code, |
| 59 const GURL& url, | 59 const GURL& url, |
| 60 bool is_https_proxy) { | 60 bool is_https_proxy) { |
| 61 if (is_https_proxy) { | 61 if (is_https_proxy) { |
| 62 UMA_HISTOGRAM_CUSTOM_ENUMERATION( | 62 UMA_HISTOGRAM_CUSTOM_ENUMERATION( |
| 63 "Net.BlockedTunnelResponse.HttpsProxy", | 63 "Net.BlockedTunnelResponse.HttpsProxy", |
| 64 HttpUtil::MapStatusCodeForHistogram(http_status_code), | 64 HttpUtil::MapStatusCodeForHistogram(http_status_code), |
| 65 HttpUtil::GetStatusCodesForHistogram()); | 65 HttpUtil::GetStatusCodesForHistogram()); |
| 66 } else { | 66 } else { |
| 67 UMA_HISTOGRAM_CUSTOM_ENUMERATION( | 67 UMA_HISTOGRAM_CUSTOM_ENUMERATION( |
| 68 "Net.BlockedTunnelResponse.HttpProxy", | 68 "Net.BlockedTunnelResponse.HttpProxy", |
| 69 HttpUtil::MapStatusCodeForHistogram(http_status_code), | 69 HttpUtil::MapStatusCodeForHistogram(http_status_code), |
| 70 HttpUtil::GetStatusCodesForHistogram()); | 70 HttpUtil::GetStatusCodesForHistogram()); |
| 71 } | 71 } |
| 72 } | 72 } |
| 73 | 73 |
| 74 // static | 74 // static |
| 75 bool ProxyClientSocket::SanitizeProxyRedirect(HttpResponseInfo* response, | 75 bool ProxyClientSocket::SanitizeProxyRedirect(HttpResponseInfo* response, |
| 76 const GURL& url) { | 76 const GURL& url) { |
| 77 DCHECK(response && response->headers); | 77 DCHECK(response && response->headers.get()); |
| 78 | 78 |
| 79 std::string location; | 79 std::string location; |
| 80 if (!response->headers->IsRedirect(&location)) | 80 if (!response->headers->IsRedirect(&location)) |
| 81 return false; | 81 return false; |
| 82 | 82 |
| 83 // Return minimal headers; set "Content-length: 0" to ignore response body. | 83 // Return minimal headers; set "Content-length: 0" to ignore response body. |
| 84 std::string fake_response_headers = | 84 std::string fake_response_headers = |
| 85 base::StringPrintf("HTTP/1.0 302 Found\n" | 85 base::StringPrintf("HTTP/1.0 302 Found\n" |
| 86 "Location: %s\n" | 86 "Location: %s\n" |
| 87 "Content-length: 0\n" | 87 "Content-length: 0\n" |
| 88 "Connection: close\n" | 88 "Connection: close\n" |
| 89 "\n", | 89 "\n", |
| 90 location.c_str()); | 90 location.c_str()); |
| 91 std::string raw_headers = | 91 std::string raw_headers = |
| 92 HttpUtil::AssembleRawHeaders(fake_response_headers.data(), | 92 HttpUtil::AssembleRawHeaders(fake_response_headers.data(), |
| 93 fake_response_headers.length()); | 93 fake_response_headers.length()); |
| 94 response->headers = new HttpResponseHeaders(raw_headers); | 94 response->headers = new HttpResponseHeaders(raw_headers); |
| 95 | 95 |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 } // namespace net | 99 } // namespace net |
| OLD | NEW |