| 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/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/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
| 11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 12 #include "net/base/auth.h" | 12 #include "net/base/auth.h" |
| 13 #include "net/base/host_port_pair.h" | 13 #include "net/base/host_port_pair.h" |
| 14 #include "net/base/io_buffer.h" | 14 #include "net/base/io_buffer.h" |
| 15 #include "net/base/net_log.h" | 15 #include "net/base/net_log.h" |
| 16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 17 #include "net/http/http_basic_stream.h" | 17 #include "net/http/http_basic_stream.h" |
| 18 #include "net/http/http_net_log_params.h" | |
| 19 #include "net/http/http_network_session.h" | 18 #include "net/http/http_network_session.h" |
| 20 #include "net/http/http_request_info.h" | 19 #include "net/http/http_request_info.h" |
| 21 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| 22 #include "net/http/http_stream_parser.h" | 21 #include "net/http/http_stream_parser.h" |
| 23 #include "net/socket/client_socket_handle.h" | 22 #include "net/socket/client_socket_handle.h" |
| 24 | 23 |
| 25 namespace net { | 24 namespace net { |
| 26 | 25 |
| 27 HttpProxyClientSocket::HttpProxyClientSocket( | 26 HttpProxyClientSocket::HttpProxyClientSocket( |
| 28 ClientSocketHandle* transport_socket, | 27 ClientSocketHandle* transport_socket, |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 | 398 |
| 400 // This is constructed lazily (instead of within our Start method), so that | 399 // This is constructed lazily (instead of within our Start method), so that |
| 401 // we have proxy info available. | 400 // we have proxy info available. |
| 402 if (request_line_.empty()) { | 401 if (request_line_.empty()) { |
| 403 DCHECK(request_headers_.IsEmpty()); | 402 DCHECK(request_headers_.IsEmpty()); |
| 404 HttpRequestHeaders authorization_headers; | 403 HttpRequestHeaders authorization_headers; |
| 405 if (auth_->HaveAuth()) | 404 if (auth_->HaveAuth()) |
| 406 auth_->AddAuthorizationHeader(&authorization_headers); | 405 auth_->AddAuthorizationHeader(&authorization_headers); |
| 407 BuildTunnelRequest(request_, authorization_headers, endpoint_, | 406 BuildTunnelRequest(request_, authorization_headers, endpoint_, |
| 408 &request_line_, &request_headers_); | 407 &request_line_, &request_headers_); |
| 409 if (net_log_.IsLoggingAllEvents()) { | 408 |
| 410 net_log_.AddEvent( | 409 net_log_.AddEvent( |
| 411 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | 410 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 412 make_scoped_refptr(new NetLogHttpRequestParameter( | 411 base::Bind(&HttpRequestHeaders::NetLogCallback, |
| 413 request_line_, request_headers_))); | 412 base::Unretained(&request_headers_), |
| 414 } | 413 &request_line_)); |
| 415 } | 414 } |
| 416 | 415 |
| 417 parser_buf_ = new GrowableIOBuffer(); | 416 parser_buf_ = new GrowableIOBuffer(); |
| 418 http_stream_parser_.reset( | 417 http_stream_parser_.reset( |
| 419 new HttpStreamParser(transport_.get(), &request_, parser_buf_, net_log_)); | 418 new HttpStreamParser(transport_.get(), &request_, parser_buf_, net_log_)); |
| 420 return http_stream_parser_->SendRequest(request_line_, request_headers_, NULL, | 419 return http_stream_parser_->SendRequest(request_line_, request_headers_, NULL, |
| 421 &response_, io_callback_); | 420 &response_, io_callback_); |
| 422 } | 421 } |
| 423 | 422 |
| 424 int HttpProxyClientSocket::DoSendRequestComplete(int result) { | 423 int HttpProxyClientSocket::DoSendRequestComplete(int result) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 435 } | 434 } |
| 436 | 435 |
| 437 int HttpProxyClientSocket::DoReadHeadersComplete(int result) { | 436 int HttpProxyClientSocket::DoReadHeadersComplete(int result) { |
| 438 if (result < 0) | 437 if (result < 0) |
| 439 return result; | 438 return result; |
| 440 | 439 |
| 441 // Require the "HTTP/1.x" status line for SSL CONNECT. | 440 // Require the "HTTP/1.x" status line for SSL CONNECT. |
| 442 if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) | 441 if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) |
| 443 return ERR_TUNNEL_CONNECTION_FAILED; | 442 return ERR_TUNNEL_CONNECTION_FAILED; |
| 444 | 443 |
| 445 if (net_log_.IsLoggingAllEvents()) { | 444 net_log_.AddEvent( |
| 446 net_log_.AddEvent( | 445 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 447 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | 446 base::Bind(&HttpResponseHeaders::NetLogCallback, response_.headers)); |
| 448 make_scoped_refptr(new NetLogHttpResponseParameter(response_.headers))); | |
| 449 } | |
| 450 | 447 |
| 451 switch (response_.headers->response_code()) { | 448 switch (response_.headers->response_code()) { |
| 452 case 200: // OK | 449 case 200: // OK |
| 453 if (http_stream_parser_->IsMoreDataBuffered()) | 450 if (http_stream_parser_->IsMoreDataBuffered()) |
| 454 // The proxy sent extraneous data after the headers. | 451 // The proxy sent extraneous data after the headers. |
| 455 return ERR_TUNNEL_CONNECTION_FAILED; | 452 return ERR_TUNNEL_CONNECTION_FAILED; |
| 456 | 453 |
| 457 next_state_ = STATE_DONE; | 454 next_state_ = STATE_DONE; |
| 458 return OK; | 455 return OK; |
| 459 | 456 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 | 509 |
| 513 int HttpProxyClientSocket::DoTCPRestartComplete(int result) { | 510 int HttpProxyClientSocket::DoTCPRestartComplete(int result) { |
| 514 if (result != OK) | 511 if (result != OK) |
| 515 return result; | 512 return result; |
| 516 | 513 |
| 517 next_state_ = STATE_GENERATE_AUTH_TOKEN; | 514 next_state_ = STATE_GENERATE_AUTH_TOKEN; |
| 518 return result; | 515 return result; |
| 519 } | 516 } |
| 520 | 517 |
| 521 } // namespace net | 518 } // namespace net |
| OLD | NEW |