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/spdy/spdy_proxy_client_socket.h" | 5 #include "net/spdy/spdy_proxy_client_socket.h" |
6 | 6 |
7 #include <algorithm> // min | 7 #include <algorithm> // min |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "net/http/proxy_connect_redirect_http_stream.h" | 21 #include "net/http/proxy_connect_redirect_http_stream.h" |
22 #include "net/spdy/spdy_http_utils.h" | 22 #include "net/spdy/spdy_http_utils.h" |
23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
24 | 24 |
25 namespace net { | 25 namespace net { |
26 | 26 |
27 SpdyProxyClientSocket::SpdyProxyClientSocket( | 27 SpdyProxyClientSocket::SpdyProxyClientSocket( |
28 const base::WeakPtr<SpdyStream>& spdy_stream, | 28 const base::WeakPtr<SpdyStream>& spdy_stream, |
29 const std::string& user_agent, | 29 const std::string& user_agent, |
30 const HostPortPair& endpoint, | 30 const HostPortPair& endpoint, |
31 const GURL& url, | |
32 const HostPortPair& proxy_server, | 31 const HostPortPair& proxy_server, |
33 const BoundNetLog& source_net_log, | 32 const BoundNetLog& source_net_log, |
34 HttpAuthCache* auth_cache, | 33 HttpAuthCache* auth_cache, |
35 HttpAuthHandlerFactory* auth_handler_factory) | 34 HttpAuthHandlerFactory* auth_handler_factory) |
36 : next_state_(STATE_DISCONNECTED), | 35 : next_state_(STATE_DISCONNECTED), |
37 spdy_stream_(spdy_stream), | 36 spdy_stream_(spdy_stream), |
38 endpoint_(endpoint), | 37 endpoint_(endpoint), |
39 auth_(new HttpAuthController(HttpAuth::AUTH_PROXY, | 38 auth_(new HttpAuthController(HttpAuth::AUTH_PROXY, |
40 GURL("https://" + proxy_server.ToString()), | 39 GURL("https://" + proxy_server.ToString()), |
41 auth_cache, | 40 auth_cache, |
42 auth_handler_factory)), | 41 auth_handler_factory)), |
| 42 user_agent_(user_agent), |
43 user_buffer_len_(0), | 43 user_buffer_len_(0), |
44 write_buffer_len_(0), | 44 write_buffer_len_(0), |
45 was_ever_used_(false), | 45 was_ever_used_(false), |
46 redirect_has_load_timing_info_(false), | 46 redirect_has_load_timing_info_(false), |
47 net_log_(BoundNetLog::Make(spdy_stream->net_log().net_log(), | 47 net_log_(BoundNetLog::Make(spdy_stream->net_log().net_log(), |
48 NetLog::SOURCE_PROXY_CLIENT_SOCKET)), | 48 NetLog::SOURCE_PROXY_CLIENT_SOCKET)), |
49 weak_factory_(this), | 49 weak_factory_(this), |
50 write_callback_weak_factory_(this) { | 50 write_callback_weak_factory_(this) { |
51 request_.method = "CONNECT"; | 51 request_.method = "CONNECT"; |
52 request_.url = url; | 52 request_.url = GURL("https://" + endpoint.ToString()); |
53 if (!user_agent.empty()) | |
54 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | |
55 user_agent); | |
56 | |
57 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, | 53 net_log_.BeginEvent(NetLog::TYPE_SOCKET_ALIVE, |
58 source_net_log.source().ToEventParametersCallback()); | 54 source_net_log.source().ToEventParametersCallback()); |
59 net_log_.AddEvent( | 55 net_log_.AddEvent( |
60 NetLog::TYPE_HTTP2_PROXY_CLIENT_SESSION, | 56 NetLog::TYPE_HTTP2_PROXY_CLIENT_SESSION, |
61 spdy_stream->net_log().source().ToEventParametersCallback()); | 57 spdy_stream->net_log().source().ToEventParametersCallback()); |
62 | 58 |
63 spdy_stream_->SetDelegate(this); | 59 spdy_stream_->SetDelegate(this); |
64 was_ever_used_ = spdy_stream_->WasEverUsed(); | 60 was_ever_used_ = spdy_stream_->WasEverUsed(); |
65 } | 61 } |
66 | 62 |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 | 342 |
347 int SpdyProxyClientSocket::DoSendRequest() { | 343 int SpdyProxyClientSocket::DoSendRequest() { |
348 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 344 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
349 | 345 |
350 // Add Proxy-Authentication header if necessary. | 346 // Add Proxy-Authentication header if necessary. |
351 HttpRequestHeaders authorization_headers; | 347 HttpRequestHeaders authorization_headers; |
352 if (auth_->HaveAuth()) { | 348 if (auth_->HaveAuth()) { |
353 auth_->AddAuthorizationHeader(&authorization_headers); | 349 auth_->AddAuthorizationHeader(&authorization_headers); |
354 } | 350 } |
355 | 351 |
356 std::string user_agent; | |
357 if (!request_.extra_headers.GetHeader(HttpRequestHeaders::kUserAgent, | |
358 &user_agent)) { | |
359 user_agent.clear(); | |
360 } | |
361 std::string request_line; | 352 std::string request_line; |
362 HttpRequestHeaders request_headers; | 353 BuildTunnelRequest(endpoint_, authorization_headers, user_agent_, |
363 BuildTunnelRequest(endpoint_, authorization_headers, user_agent, | 354 &request_line, &request_.extra_headers); |
364 &request_line, &request_headers); | |
365 | 355 |
366 net_log_.AddEvent( | 356 net_log_.AddEvent( |
367 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | 357 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
368 base::Bind(&HttpRequestHeaders::NetLogCallback, | 358 base::Bind(&HttpRequestHeaders::NetLogCallback, |
369 base::Unretained(&request_headers), | 359 base::Unretained(&request_.extra_headers), &request_line)); |
370 &request_line)); | |
371 | 360 |
372 request_.extra_headers.MergeFrom(request_headers); | |
373 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 361 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); |
374 CreateSpdyHeadersFromHttpRequest(request_, request_headers, | 362 CreateSpdyHeadersFromHttpRequest(request_, request_.extra_headers, |
375 spdy_stream_->GetProtocolVersion(), true, | 363 spdy_stream_->GetProtocolVersion(), true, |
376 headers.get()); | 364 headers.get()); |
377 // Reset the URL to be the endpoint of the connection | 365 // Reset the URL to be the endpoint of the connection |
378 if (spdy_stream_->GetProtocolVersion() > 2) { | 366 if (spdy_stream_->GetProtocolVersion() > 2) { |
379 (*headers)[":path"] = endpoint_.ToString(); | 367 (*headers)[":path"] = endpoint_.ToString(); |
380 headers->erase(":scheme"); | 368 headers->erase(":scheme"); |
381 } else { | 369 } else { |
382 (*headers)["url"] = endpoint_.ToString(); | 370 (*headers)["url"] = endpoint_.ToString(); |
383 headers->erase("scheme"); | 371 headers->erase("scheme"); |
384 } | 372 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 } else if (!read_callback_.is_null()) { | 523 } else if (!read_callback_.is_null()) { |
536 // If we have a read_callback_, the we need to make sure we call it back. | 524 // If we have a read_callback_, the we need to make sure we call it back. |
537 OnDataReceived(scoped_ptr<SpdyBuffer>()); | 525 OnDataReceived(scoped_ptr<SpdyBuffer>()); |
538 } | 526 } |
539 // This may have been deleted by read_callback_, so check first. | 527 // This may have been deleted by read_callback_, so check first. |
540 if (weak_ptr.get() && !write_callback.is_null()) | 528 if (weak_ptr.get() && !write_callback.is_null()) |
541 write_callback.Run(ERR_CONNECTION_CLOSED); | 529 write_callback.Run(ERR_CONNECTION_CLOSED); |
542 } | 530 } |
543 | 531 |
544 } // namespace net | 532 } // namespace net |
OLD | NEW |