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

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: Reworked HaveAuth test 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
« no previous file with comments | « net/http/http_proxy_client_socket.h ('k') | net/http/http_proxy_client_socket_pool.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "net/base/auth.h" 11 #include "net/base/auth.h"
12 #include "net/base/host_port_pair.h" 12 #include "net/base/host_port_pair.h"
13 #include "net/base/io_buffer.h" 13 #include "net/base/io_buffer.h"
14 #include "net/base/net_log.h" 14 #include "net/base/net_log.h"
15 #include "net/base/net_util.h" 15 #include "net/base/net_util.h"
16 #include "net/base/proxy_delegate.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 ProxyDelegate* proxy_delegate,
38 bool is_https_proxy) 40 bool is_https_proxy)
39 : io_callback_(base::Bind(&HttpProxyClientSocket::OnIOComplete, 41 : io_callback_(base::Bind(&HttpProxyClientSocket::OnIOComplete,
40 base::Unretained(this))), 42 base::Unretained(this))),
41 next_state_(STATE_NONE), 43 next_state_(STATE_NONE),
42 transport_(transport_socket), 44 transport_(transport_socket),
43 endpoint_(endpoint), 45 endpoint_(endpoint),
44 auth_(tunnel ? 46 auth_(tunnel ?
45 new HttpAuthController(HttpAuth::AUTH_PROXY, 47 new HttpAuthController(HttpAuth::AUTH_PROXY,
46 GURL((is_https_proxy ? "https://" : "http://") 48 GURL((is_https_proxy ? "https://" : "http://")
47 + proxy_server.ToString()), 49 + proxy_server.ToString()),
48 http_auth_cache, 50 http_auth_cache,
49 http_auth_handler_factory) 51 http_auth_handler_factory)
50 : NULL), 52 : NULL),
51 tunnel_(tunnel), 53 tunnel_(tunnel),
52 using_spdy_(using_spdy), 54 using_spdy_(using_spdy),
53 protocol_negotiated_(protocol_negotiated), 55 protocol_negotiated_(protocol_negotiated),
54 is_https_proxy_(is_https_proxy), 56 is_https_proxy_(is_https_proxy),
55 redirect_has_load_timing_info_(false), 57 redirect_has_load_timing_info_(false),
58 proxy_server_(proxy_server),
59 proxy_delegate_(proxy_delegate),
56 net_log_(transport_socket->socket()->NetLog()) { 60 net_log_(transport_socket->socket()->NetLog()) {
57 // Synthesize the bits of a request that we actually use. 61 // Synthesize the bits of a request that we actually use.
58 request_.url = request_url; 62 request_.url = request_url;
59 request_.method = "GET"; 63 request_.method = "GET";
60 if (!user_agent.empty()) 64 if (!user_agent.empty())
61 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, 65 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent,
62 user_agent); 66 user_agent);
63 } 67 }
64 68
65 HttpProxyClientSocket::~HttpProxyClientSocket() { 69 HttpProxyClientSocket::~HttpProxyClientSocket() {
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 int HttpProxyClientSocket::DoSendRequest() { 402 int HttpProxyClientSocket::DoSendRequest() {
399 next_state_ = STATE_SEND_REQUEST_COMPLETE; 403 next_state_ = STATE_SEND_REQUEST_COMPLETE;
400 404
401 // This is constructed lazily (instead of within our Start method), so that 405 // This is constructed lazily (instead of within our Start method), so that
402 // we have proxy info available. 406 // we have proxy info available.
403 if (request_line_.empty()) { 407 if (request_line_.empty()) {
404 DCHECK(request_headers_.IsEmpty()); 408 DCHECK(request_headers_.IsEmpty());
405 HttpRequestHeaders authorization_headers; 409 HttpRequestHeaders authorization_headers;
406 if (auth_->HaveAuth()) 410 if (auth_->HaveAuth())
407 auth_->AddAuthorizationHeader(&authorization_headers); 411 auth_->AddAuthorizationHeader(&authorization_headers);
412 if (proxy_delegate_) {
413 proxy_delegate_->OnBeforeTunnelRequest(proxy_server_,
414 &authorization_headers);
415 }
408 BuildTunnelRequest(request_, authorization_headers, endpoint_, 416 BuildTunnelRequest(request_, authorization_headers, endpoint_,
409 &request_line_, &request_headers_); 417 &request_line_, &request_headers_);
410 418
411 net_log_.AddEvent( 419 net_log_.AddEvent(
412 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, 420 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS,
413 base::Bind(&HttpRequestHeaders::NetLogCallback, 421 base::Bind(&HttpRequestHeaders::NetLogCallback,
414 base::Unretained(&request_headers_), 422 base::Unretained(&request_headers_),
415 &request_line_)); 423 &request_line_));
416 } 424 }
417 425
(...skipping 22 matching lines...) Expand all
440 return result; 448 return result;
441 449
442 // Require the "HTTP/1.x" status line for SSL CONNECT. 450 // Require the "HTTP/1.x" status line for SSL CONNECT.
443 if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) 451 if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0))
444 return ERR_TUNNEL_CONNECTION_FAILED; 452 return ERR_TUNNEL_CONNECTION_FAILED;
445 453
446 net_log_.AddEvent( 454 net_log_.AddEvent(
447 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, 455 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS,
448 base::Bind(&HttpResponseHeaders::NetLogCallback, response_.headers)); 456 base::Bind(&HttpResponseHeaders::NetLogCallback, response_.headers));
449 457
458 if (proxy_delegate_) {
459 proxy_delegate_->OnTunnelHeadersReceived(
460 HostPortPair::FromURL(request_.url),
461 proxy_server_,
462 *response_.headers);
463 }
464
450 switch (response_.headers->response_code()) { 465 switch (response_.headers->response_code()) {
451 case 200: // OK 466 case 200: // OK
452 if (http_stream_parser_->IsMoreDataBuffered()) 467 if (http_stream_parser_->IsMoreDataBuffered())
453 // The proxy sent extraneous data after the headers. 468 // The proxy sent extraneous data after the headers.
454 return ERR_TUNNEL_CONNECTION_FAILED; 469 return ERR_TUNNEL_CONNECTION_FAILED;
455 470
456 next_state_ = STATE_DONE; 471 next_state_ = STATE_DONE;
457 return OK; 472 return OK;
458 473
459 // We aren't able to CONNECT to the remote host through the proxy. We 474 // We aren't able to CONNECT to the remote host through the proxy. We
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 544
530 int HttpProxyClientSocket::DoTCPRestartComplete(int result) { 545 int HttpProxyClientSocket::DoTCPRestartComplete(int result) {
531 if (result != OK) 546 if (result != OK)
532 return result; 547 return result;
533 548
534 next_state_ = STATE_GENERATE_AUTH_TOKEN; 549 next_state_ = STATE_GENERATE_AUTH_TOKEN;
535 return result; 550 return result;
536 } 551 }
537 552
538 } // namespace net 553 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_proxy_client_socket.h ('k') | net/http/http_proxy_client_socket_pool.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698