1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "net/http/http_proxy_utils.h" 6 7 #include "base/string_util.h" 8 #include "googleurl/src/gurl.h" 9 #include "net/base/host_port_pair.h" 10 #include "net/base/net_util.h" 11 #include "net/http/http_request_info.h" 12 13 namespace net { 14 15 void BuildTunnelRequest( 16 const HttpRequestInfo& request_info, 17 const HttpRequestHeaders& auth_headers, 18 const HostPortPair& endpoint, 19 std::string* request_line, 20 HttpRequestHeaders* request_headers) { 21 // RFC 2616 Section 9 says the Host request-header field MUST accompany all 22 // HTTP/1.1 requests. Add "Proxy-Connection: keep-alive" for compat with 23 // HTTP/1.0 proxies such as Squid (required for NTLM authentication). 24 *request_line = StringPrintf( 25 "CONNECT %s HTTP/1.1\r\n", endpoint.ToString().c_str()); 26 request_headers->SetHeader(HttpRequestHeaders::kHost, 27 GetHostAndOptionalPort(request_info.url)); 28 request_headers->SetHeader(HttpRequestHeaders::kProxyConnection, 29 "keep-alive"); 30 31 std::string user_agent; 32 if (request_info.extra_headers.GetHeader(HttpRequestHeaders::kUserAgent, 33 &user_agent)) 34 request_headers->SetHeader(HttpRequestHeaders::kUserAgent, user_agent); 35 36 request_headers->MergeFrom(auth_headers); 37 } 38 39 } // namespace net 40