| 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" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 bool HttpProxyClientSocket::IsUsingSpdy() const { | 89 bool HttpProxyClientSocket::IsUsingSpdy() const { |
| 90 return using_spdy_; | 90 return using_spdy_; |
| 91 } | 91 } |
| 92 | 92 |
| 93 NextProto HttpProxyClientSocket::GetProtocolNegotiated() const { | 93 NextProto HttpProxyClientSocket::GetProtocolNegotiated() const { |
| 94 return protocol_negotiated_; | 94 return protocol_negotiated_; |
| 95 } | 95 } |
| 96 | 96 |
| 97 const HttpResponseInfo* HttpProxyClientSocket::GetConnectResponseInfo() const { | 97 const HttpResponseInfo* HttpProxyClientSocket::GetConnectResponseInfo() const { |
| 98 return response_.headers ? &response_ : NULL; | 98 return response_.headers.get() ? &response_ : NULL; |
| 99 } | 99 } |
| 100 | 100 |
| 101 HttpStream* HttpProxyClientSocket::CreateConnectResponseStream() { | 101 HttpStream* HttpProxyClientSocket::CreateConnectResponseStream() { |
| 102 return new HttpBasicStream(transport_.release(), | 102 return new HttpBasicStream(transport_.release(), |
| 103 http_stream_parser_.release(), false); | 103 http_stream_parser_.release(), false); |
| 104 } | 104 } |
| 105 | 105 |
| 106 | 106 |
| 107 int HttpProxyClientSocket::Connect(const CompletionCallback& callback) { | 107 int HttpProxyClientSocket::Connect(const CompletionCallback& callback) { |
| 108 DCHECK(transport_.get()); | 108 DCHECK(transport_.get()); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 &request_line_, &request_headers_); | 407 &request_line_, &request_headers_); |
| 408 | 408 |
| 409 net_log_.AddEvent( | 409 net_log_.AddEvent( |
| 410 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | 410 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 411 base::Bind(&HttpRequestHeaders::NetLogCallback, | 411 base::Bind(&HttpRequestHeaders::NetLogCallback, |
| 412 base::Unretained(&request_headers_), | 412 base::Unretained(&request_headers_), |
| 413 &request_line_)); | 413 &request_line_)); |
| 414 } | 414 } |
| 415 | 415 |
| 416 parser_buf_ = new GrowableIOBuffer(); | 416 parser_buf_ = new GrowableIOBuffer(); |
| 417 http_stream_parser_.reset( | 417 http_stream_parser_.reset(new HttpStreamParser( |
| 418 new HttpStreamParser(transport_.get(), &request_, parser_buf_, net_log_)); | 418 transport_.get(), &request_, parser_buf_.get(), net_log_)); |
| 419 return http_stream_parser_->SendRequest( | 419 return http_stream_parser_->SendRequest( |
| 420 request_line_, request_headers_, &response_, io_callback_); | 420 request_line_, request_headers_, &response_, io_callback_); |
| 421 } | 421 } |
| 422 | 422 |
| 423 int HttpProxyClientSocket::DoSendRequestComplete(int result) { | 423 int HttpProxyClientSocket::DoSendRequestComplete(int result) { |
| 424 if (result < 0) | 424 if (result < 0) |
| 425 return result; | 425 return result; |
| 426 | 426 |
| 427 next_state_ = STATE_READ_HEADERS; | 427 next_state_ = STATE_READ_HEADERS; |
| 428 return OK; | 428 return OK; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 | 471 |
| 472 // We're not using an HTTPS proxy, or we couldn't sanitize the redirect. | 472 // We're not using an HTTPS proxy, or we couldn't sanitize the redirect. |
| 473 LogBlockedTunnelResponse(); | 473 LogBlockedTunnelResponse(); |
| 474 return ERR_TUNNEL_CONNECTION_FAILED; | 474 return ERR_TUNNEL_CONNECTION_FAILED; |
| 475 | 475 |
| 476 case 407: // Proxy Authentication Required | 476 case 407: // Proxy Authentication Required |
| 477 // We need this status code to allow proxy authentication. Our | 477 // We need this status code to allow proxy authentication. Our |
| 478 // authentication code is smart enough to avoid being tricked by an | 478 // authentication code is smart enough to avoid being tricked by an |
| 479 // active network attacker. | 479 // active network attacker. |
| 480 // The next state is intentionally not set as it should be STATE_NONE; | 480 // The next state is intentionally not set as it should be STATE_NONE; |
| 481 return HandleProxyAuthChallenge(auth_, &response_, net_log_); | 481 return HandleProxyAuthChallenge(auth_.get(), &response_, net_log_); |
| 482 | 482 |
| 483 default: | 483 default: |
| 484 // Ignore response to avoid letting the proxy impersonate the target | 484 // Ignore response to avoid letting the proxy impersonate the target |
| 485 // server. (See http://crbug.com/137891.) | 485 // server. (See http://crbug.com/137891.) |
| 486 // We lose something by doing this. We have seen proxy 403, 404, and | 486 // We lose something by doing this. We have seen proxy 403, 404, and |
| 487 // 501 response bodies that contain a useful error message. For | 487 // 501 response bodies that contain a useful error message. For |
| 488 // example, Squid uses a 404 response to report the DNS error: "The | 488 // example, Squid uses a 404 response to report the DNS error: "The |
| 489 // domain name does not exist." | 489 // domain name does not exist." |
| 490 LogBlockedTunnelResponse(); | 490 LogBlockedTunnelResponse(); |
| 491 return ERR_TUNNEL_CONNECTION_FAILED; | 491 return ERR_TUNNEL_CONNECTION_FAILED; |
| 492 } | 492 } |
| 493 } | 493 } |
| 494 | 494 |
| 495 int HttpProxyClientSocket::DoDrainBody() { | 495 int HttpProxyClientSocket::DoDrainBody() { |
| 496 DCHECK(drain_buf_); | 496 DCHECK(drain_buf_.get()); |
| 497 DCHECK(transport_->is_initialized()); | 497 DCHECK(transport_->is_initialized()); |
| 498 next_state_ = STATE_DRAIN_BODY_COMPLETE; | 498 next_state_ = STATE_DRAIN_BODY_COMPLETE; |
| 499 return http_stream_parser_->ReadResponseBody(drain_buf_, kDrainBodyBufferSize, | 499 return http_stream_parser_->ReadResponseBody( |
| 500 io_callback_); | 500 drain_buf_.get(), kDrainBodyBufferSize, io_callback_); |
| 501 } | 501 } |
| 502 | 502 |
| 503 int HttpProxyClientSocket::DoDrainBodyComplete(int result) { | 503 int HttpProxyClientSocket::DoDrainBodyComplete(int result) { |
| 504 if (result < 0) | 504 if (result < 0) |
| 505 return result; | 505 return result; |
| 506 | 506 |
| 507 if (http_stream_parser_->IsResponseBodyComplete()) | 507 if (http_stream_parser_->IsResponseBodyComplete()) |
| 508 return DidDrainBodyForAuthRestart(true); | 508 return DidDrainBodyForAuthRestart(true); |
| 509 | 509 |
| 510 // Keep draining. | 510 // Keep draining. |
| 511 next_state_ = STATE_DRAIN_BODY; | 511 next_state_ = STATE_DRAIN_BODY; |
| 512 return OK; | 512 return OK; |
| 513 } | 513 } |
| 514 | 514 |
| 515 int HttpProxyClientSocket::DoTCPRestart() { | 515 int HttpProxyClientSocket::DoTCPRestart() { |
| 516 next_state_ = STATE_TCP_RESTART_COMPLETE; | 516 next_state_ = STATE_TCP_RESTART_COMPLETE; |
| 517 return transport_->socket()->Connect( | 517 return transport_->socket()->Connect( |
| 518 base::Bind(&HttpProxyClientSocket::OnIOComplete, base::Unretained(this))); | 518 base::Bind(&HttpProxyClientSocket::OnIOComplete, base::Unretained(this))); |
| 519 } | 519 } |
| 520 | 520 |
| 521 int HttpProxyClientSocket::DoTCPRestartComplete(int result) { | 521 int HttpProxyClientSocket::DoTCPRestartComplete(int result) { |
| 522 if (result != OK) | 522 if (result != OK) |
| 523 return result; | 523 return result; |
| 524 | 524 |
| 525 next_state_ = STATE_GENERATE_AUTH_TOKEN; | 525 next_state_ = STATE_GENERATE_AUTH_TOKEN; |
| 526 return result; | 526 return result; |
| 527 } | 527 } |
| 528 | 528 |
| 529 } // namespace net | 529 } // namespace net |
| OLD | NEW |