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

Side by Side Diff: net/http/http_proxy_client_socket.cc

Issue 517693002: Add embedder-specific headers to HTTP CONNECT tunnel request (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added tests Created 6 years, 3 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 unified diff | Download patch
OLDNEW
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/http_proxy_client_socket.h" 5 #include "net/http/http_proxy_client_socket.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
9 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 11 #include "base/strings/stringprintf.h"
11 #include "net/base/auth.h" 12 #include "net/base/auth.h"
12 #include "net/base/host_port_pair.h" 13 #include "net/base/host_port_pair.h"
13 #include "net/base/io_buffer.h" 14 #include "net/base/io_buffer.h"
14 #include "net/base/net_log.h" 15 #include "net/base/net_log.h"
15 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
16 #include "net/http/http_basic_stream.h" 17 #include "net/http/http_basic_stream.h"
17 #include "net/http/http_network_session.h" 18 #include "net/http/http_network_session.h"
18 #include "net/http/http_request_info.h" 19 #include "net/http/http_request_info.h"
19 #include "net/http/http_response_headers.h" 20 #include "net/http/http_response_headers.h"
20 #include "net/http/http_stream_parser.h" 21 #include "net/http/http_stream_parser.h"
21 #include "net/http/proxy_connect_redirect_http_stream.h" 22 #include "net/http/proxy_connect_redirect_http_stream.h"
22 #include "net/socket/client_socket_handle.h" 23 #include "net/socket/client_socket_handle.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 25
25 namespace net { 26 namespace net {
26 27
27 HttpProxyClientSocket::HttpProxyClientSocket( 28 HttpProxyClientSocket::HttpProxyClientSocket(
28 ClientSocketHandle* transport_socket, 29 ClientSocketHandle* transport_socket,
29 const GURL& request_url, 30 const GURL& request_url,
30 const std::string& user_agent, 31 const std::string& user_agent,
31 const HostPortPair& endpoint, 32 const HostPortPair& endpoint,
32 const HostPortPair& proxy_server, 33 const HostPortPair& proxy_server,
33 HttpAuthCache* http_auth_cache, 34 HttpAuthCache* http_auth_cache,
34 HttpAuthHandlerFactory* http_auth_handler_factory, 35 HttpAuthHandlerFactory* http_auth_handler_factory,
35 bool tunnel, 36 bool tunnel,
36 bool using_spdy, 37 bool using_spdy,
37 NextProto protocol_negotiated, 38 NextProto protocol_negotiated,
39 const base::Callback<void(const HostPortPair&, HttpRequestHeaders*)>&
40 before_proxy_tunnel_request_callback,
38 bool is_https_proxy) 41 bool is_https_proxy)
39 : io_callback_(base::Bind(&HttpProxyClientSocket::OnIOComplete, 42 : io_callback_(base::Bind(&HttpProxyClientSocket::OnIOComplete,
40 base::Unretained(this))), 43 base::Unretained(this))),
41 next_state_(STATE_NONE), 44 next_state_(STATE_NONE),
42 transport_(transport_socket), 45 transport_(transport_socket),
43 endpoint_(endpoint), 46 endpoint_(endpoint),
44 auth_(tunnel ? 47 auth_(tunnel ?
45 new HttpAuthController(HttpAuth::AUTH_PROXY, 48 new HttpAuthController(HttpAuth::AUTH_PROXY,
46 GURL((is_https_proxy ? "https://" : "http://") 49 GURL((is_https_proxy ? "https://" : "http://")
47 + proxy_server.ToString()), 50 + proxy_server.ToString()),
48 http_auth_cache, 51 http_auth_cache,
49 http_auth_handler_factory) 52 http_auth_handler_factory)
50 : NULL), 53 : NULL),
51 tunnel_(tunnel), 54 tunnel_(tunnel),
52 using_spdy_(using_spdy), 55 using_spdy_(using_spdy),
53 protocol_negotiated_(protocol_negotiated), 56 protocol_negotiated_(protocol_negotiated),
54 is_https_proxy_(is_https_proxy), 57 is_https_proxy_(is_https_proxy),
55 redirect_has_load_timing_info_(false), 58 redirect_has_load_timing_info_(false),
59 proxy_server_(proxy_server),
60 before_proxy_tunnel_request_callback_(
61 before_proxy_tunnel_request_callback),
56 net_log_(transport_socket->socket()->NetLog()) { 62 net_log_(transport_socket->socket()->NetLog()) {
57 // Synthesize the bits of a request that we actually use. 63 // Synthesize the bits of a request that we actually use.
58 request_.url = request_url; 64 request_.url = request_url;
59 request_.method = "GET"; 65 request_.method = "GET";
60 if (!user_agent.empty()) 66 if (!user_agent.empty())
61 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, 67 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
62 user_agent); 68 user_agent);
63 } 69 }
64 70
65 HttpProxyClientSocket::~HttpProxyClientSocket() { 71 HttpProxyClientSocket::~HttpProxyClientSocket() {
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 } 402 }
397 403
398 int HttpProxyClientSocket::DoSendRequest() { 404 int HttpProxyClientSocket::DoSendRequest() {
399 next_state_ = STATE_SEND_REQUEST_COMPLETE; 405 next_state_ = STATE_SEND_REQUEST_COMPLETE;
400 406
401 // This is constructed lazily (instead of within our Start method), so that 407 // This is constructed lazily (instead of within our Start method), so that
402 // we have proxy info available. 408 // we have proxy info available.
403 if (request_line_.empty()) { 409 if (request_line_.empty()) {
404 DCHECK(request_headers_.IsEmpty()); 410 DCHECK(request_headers_.IsEmpty());
405 HttpRequestHeaders authorization_headers; 411 HttpRequestHeaders authorization_headers;
412 if (!before_proxy_tunnel_request_callback_.is_null()) {
413 before_proxy_tunnel_request_callback_.Run(proxy_server_,
414 &authorization_headers);
415 }
406 if (auth_->HaveAuth()) 416 if (auth_->HaveAuth())
407 auth_->AddAuthorizationHeader(&authorization_headers); 417 auth_->AddAuthorizationHeader(&authorization_headers);
408 BuildTunnelRequest(request_, authorization_headers, endpoint_, 418 BuildTunnelRequest(request_, authorization_headers, endpoint_,
409 &request_line_, &request_headers_); 419 &request_line_, &request_headers_);
410 420
411 net_log_.AddEvent( 421 net_log_.AddEvent(
412 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, 422 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
413 base::Bind(&HttpRequestHeaders::NetLogCallback, 423 base::Bind(&HttpRequestHeaders::NetLogCallback,
414 base::Unretained(&request_headers_), 424 base::Unretained(&request_headers_),
415 &request_line_)); 425 &request_line_));
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 539
530 int HttpProxyClientSocket::DoTCPRestartComplete(int result) { 540 int HttpProxyClientSocket::DoTCPRestartComplete(int result) {
531 if (result != OK) 541 if (result != OK)
532 return result; 542 return result;
533 543
534 next_state_ = STATE_GENERATE_AUTH_TOKEN; 544 next_state_ = STATE_GENERATE_AUTH_TOKEN;
535 return result; 545 return result;
536 } 546 }
537 547
538 } // namespace net 548 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698