| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "googleurl/src/gurl.h" | 13 #include "googleurl/src/gurl.h" |
| 14 #include "net/base/auth.h" | 14 #include "net/base/auth.h" |
| 15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 17 #include "net/http/http_auth_cache.h" | 17 #include "net/http/http_auth_cache.h" |
| 18 #include "net/http/http_auth_handler_factory.h" | 18 #include "net/http/http_auth_handler_factory.h" |
| 19 #include "net/http/http_net_log_params.h" | |
| 20 #include "net/http/http_response_headers.h" | 19 #include "net/http/http_response_headers.h" |
| 21 #include "net/spdy/spdy_http_utils.h" | 20 #include "net/spdy/spdy_http_utils.h" |
| 22 | 21 |
| 23 namespace net { | 22 namespace net { |
| 24 | 23 |
| 25 SpdyProxyClientSocket::SpdyProxyClientSocket( | 24 SpdyProxyClientSocket::SpdyProxyClientSocket( |
| 26 SpdyStream* spdy_stream, | 25 SpdyStream* spdy_stream, |
| 27 const std::string& user_agent, | 26 const std::string& user_agent, |
| 28 const HostPortPair& endpoint, | 27 const HostPortPair& endpoint, |
| 29 const GURL& url, | 28 const GURL& url, |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // Add Proxy-Authentication header if necessary. | 357 // Add Proxy-Authentication header if necessary. |
| 359 HttpRequestHeaders authorization_headers; | 358 HttpRequestHeaders authorization_headers; |
| 360 if (auth_->HaveAuth()) { | 359 if (auth_->HaveAuth()) { |
| 361 auth_->AddAuthorizationHeader(&authorization_headers); | 360 auth_->AddAuthorizationHeader(&authorization_headers); |
| 362 } | 361 } |
| 363 | 362 |
| 364 std::string request_line; | 363 std::string request_line; |
| 365 HttpRequestHeaders request_headers; | 364 HttpRequestHeaders request_headers; |
| 366 BuildTunnelRequest(request_, authorization_headers, endpoint_, &request_line, | 365 BuildTunnelRequest(request_, authorization_headers, endpoint_, &request_line, |
| 367 &request_headers); | 366 &request_headers); |
| 368 if (net_log_.IsLoggingAllEvents()) { | 367 |
| 369 net_log_.AddEvent( | 368 net_log_.AddEvent( |
| 370 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | 369 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 371 make_scoped_refptr(new NetLogHttpRequestParameter( | 370 base::Bind(&HttpRequestHeaders::NetLogCallback, |
| 372 request_line, request_headers))); | 371 base::Unretained(&request_headers), |
| 373 } | 372 &request_line)); |
| 374 | 373 |
| 375 request_.extra_headers.MergeFrom(request_headers); | 374 request_.extra_headers.MergeFrom(request_headers); |
| 376 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 375 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); |
| 377 CreateSpdyHeadersFromHttpRequest(request_, request_headers, headers.get(), | 376 CreateSpdyHeadersFromHttpRequest(request_, request_headers, headers.get(), |
| 378 spdy_stream_->GetProtocolVersion(), true); | 377 spdy_stream_->GetProtocolVersion(), true); |
| 379 // Reset the URL to be the endpoint of the connection | 378 // Reset the URL to be the endpoint of the connection |
| 380 if (spdy_stream_->GetProtocolVersion() > 2) { | 379 if (spdy_stream_->GetProtocolVersion() > 2) { |
| 381 (*headers)[":path"] = endpoint_.ToString(); | 380 (*headers)[":path"] = endpoint_.ToString(); |
| 382 headers->erase(":scheme"); | 381 headers->erase(":scheme"); |
| 383 } else { | 382 } else { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 403 // we are notified by a callback when the SYN_REPLY frame arrives | 402 // we are notified by a callback when the SYN_REPLY frame arrives |
| 404 | 403 |
| 405 if (result < 0) | 404 if (result < 0) |
| 406 return result; | 405 return result; |
| 407 | 406 |
| 408 // Require the "HTTP/1.x" status line for SSL CONNECT. | 407 // Require the "HTTP/1.x" status line for SSL CONNECT. |
| 409 if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) | 408 if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) |
| 410 return ERR_TUNNEL_CONNECTION_FAILED; | 409 return ERR_TUNNEL_CONNECTION_FAILED; |
| 411 | 410 |
| 412 next_state_ = STATE_OPEN; | 411 next_state_ = STATE_OPEN; |
| 413 if (net_log_.IsLoggingAllEvents()) { | 412 net_log_.AddEvent( |
| 414 net_log_.AddEvent( | 413 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 415 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | 414 base::Bind(&HttpResponseHeaders::NetLogCallback, response_.headers)); |
| 416 make_scoped_refptr(new NetLogHttpResponseParameter(response_.headers))); | |
| 417 } | |
| 418 | 415 |
| 419 if (response_.headers->response_code() == 200) { | 416 if (response_.headers->response_code() == 200) { |
| 420 return OK; | 417 return OK; |
| 421 } else if (response_.headers->response_code() == 407) { | 418 } else if (response_.headers->response_code() == 407) { |
| 422 return HandleProxyAuthChallenge(auth_, &response_, net_log_); | 419 return HandleProxyAuthChallenge(auth_, &response_, net_log_); |
| 423 } else { | 420 } else { |
| 424 // Immediately hand off our SpdyStream to a newly created SpdyHttpStream | 421 // Immediately hand off our SpdyStream to a newly created SpdyHttpStream |
| 425 // so that any subsequent SpdyFrames are processed in the context of | 422 // so that any subsequent SpdyFrames are processed in the context of |
| 426 // the HttpStream, not the socket. | 423 // the HttpStream, not the socket. |
| 427 DCHECK(spdy_stream_); | 424 DCHECK(spdy_stream_); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 } | 544 } |
| 548 // This may have been deleted by read_callback_, so check first. | 545 // This may have been deleted by read_callback_, so check first. |
| 549 if (weak_ptr && !write_callback.is_null()) | 546 if (weak_ptr && !write_callback.is_null()) |
| 550 write_callback.Run(ERR_CONNECTION_CLOSED); | 547 write_callback.Run(ERR_CONNECTION_CLOSED); |
| 551 } | 548 } |
| 552 | 549 |
| 553 void SpdyProxyClientSocket::set_chunk_callback(ChunkCallback* /*callback*/) { | 550 void SpdyProxyClientSocket::set_chunk_callback(ChunkCallback* /*callback*/) { |
| 554 } | 551 } |
| 555 | 552 |
| 556 } // namespace net | 553 } // namespace net |
| OLD | NEW |