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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 | 90 |
91 bool HttpProxyClientSocket::IsUsingSpdy() const { | 91 bool HttpProxyClientSocket::IsUsingSpdy() const { |
92 return using_spdy_; | 92 return using_spdy_; |
93 } | 93 } |
94 | 94 |
95 NextProto HttpProxyClientSocket::GetProtocolNegotiated() const { | 95 NextProto HttpProxyClientSocket::GetProtocolNegotiated() const { |
96 return protocol_negotiated_; | 96 return protocol_negotiated_; |
97 } | 97 } |
98 | 98 |
99 const HttpResponseInfo* HttpProxyClientSocket::GetConnectResponseInfo() const { | 99 const HttpResponseInfo* HttpProxyClientSocket::GetConnectResponseInfo() const { |
100 return response_.headers ? &response_ : NULL; | 100 return response_.headers.get() ? &response_ : NULL; |
101 } | 101 } |
102 | 102 |
103 HttpStream* HttpProxyClientSocket::CreateConnectResponseStream() { | 103 HttpStream* HttpProxyClientSocket::CreateConnectResponseStream() { |
104 return new HttpBasicStream(transport_.release(), | 104 return new HttpBasicStream(transport_.release(), |
105 http_stream_parser_.release(), false); | 105 http_stream_parser_.release(), false); |
106 } | 106 } |
107 | 107 |
108 | 108 |
109 int HttpProxyClientSocket::Connect(const CompletionCallback& callback) { | 109 int HttpProxyClientSocket::Connect(const CompletionCallback& callback) { |
110 DCHECK(transport_.get()); | 110 DCHECK(transport_.get()); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 426 |
427 net_log_.AddEvent( | 427 net_log_.AddEvent( |
428 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, | 428 NetLog::TYPE_HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
429 base::Bind(&HttpRequestHeaders::NetLogCallback, | 429 base::Bind(&HttpRequestHeaders::NetLogCallback, |
430 base::Unretained(&request_headers_), | 430 base::Unretained(&request_headers_), |
431 &request_line_)); | 431 &request_line_)); |
432 } | 432 } |
433 | 433 |
434 parser_buf_ = new GrowableIOBuffer(); | 434 parser_buf_ = new GrowableIOBuffer(); |
435 http_stream_parser_.reset( | 435 http_stream_parser_.reset( |
436 new HttpStreamParser(transport_.get(), &request_, parser_buf_, net_log_)); | 436 new HttpStreamParser( |
| 437 transport_.get(), &request_, parser_buf_.get(), net_log_)); |
437 return http_stream_parser_->SendRequest( | 438 return http_stream_parser_->SendRequest( |
438 request_line_, request_headers_, scoped_ptr<UploadDataStream>(), | 439 request_line_, request_headers_, scoped_ptr<UploadDataStream>(), |
439 &response_, io_callback_); | 440 &response_, io_callback_); |
440 } | 441 } |
441 | 442 |
442 int HttpProxyClientSocket::DoSendRequestComplete(int result) { | 443 int HttpProxyClientSocket::DoSendRequestComplete(int result) { |
443 if (result < 0) | 444 if (result < 0) |
444 return result; | 445 return result; |
445 | 446 |
446 next_state_ = STATE_READ_HEADERS; | 447 next_state_ = STATE_READ_HEADERS; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 | 491 |
491 // We're not using an HTTPS proxy, or we couldn't sanitize the redirect. | 492 // We're not using an HTTPS proxy, or we couldn't sanitize the redirect. |
492 LogBlockedTunnelResponse(); | 493 LogBlockedTunnelResponse(); |
493 return ERR_TUNNEL_CONNECTION_FAILED; | 494 return ERR_TUNNEL_CONNECTION_FAILED; |
494 | 495 |
495 case 407: // Proxy Authentication Required | 496 case 407: // Proxy Authentication Required |
496 // We need this status code to allow proxy authentication. Our | 497 // We need this status code to allow proxy authentication. Our |
497 // authentication code is smart enough to avoid being tricked by an | 498 // authentication code is smart enough to avoid being tricked by an |
498 // active network attacker. | 499 // active network attacker. |
499 // The next state is intentionally not set as it should be STATE_NONE; | 500 // The next state is intentionally not set as it should be STATE_NONE; |
500 return HandleProxyAuthChallenge(auth_, &response_, net_log_); | 501 return HandleProxyAuthChallenge(auth_.get(), &response_, net_log_); |
501 | 502 |
502 default: | 503 default: |
503 // Ignore response to avoid letting the proxy impersonate the target | 504 // Ignore response to avoid letting the proxy impersonate the target |
504 // server. (See http://crbug.com/137891.) | 505 // server. (See http://crbug.com/137891.) |
505 // We lose something by doing this. We have seen proxy 403, 404, and | 506 // We lose something by doing this. We have seen proxy 403, 404, and |
506 // 501 response bodies that contain a useful error message. For | 507 // 501 response bodies that contain a useful error message. For |
507 // example, Squid uses a 404 response to report the DNS error: "The | 508 // example, Squid uses a 404 response to report the DNS error: "The |
508 // domain name does not exist." | 509 // domain name does not exist." |
509 LogBlockedTunnelResponse(); | 510 LogBlockedTunnelResponse(); |
510 return ERR_TUNNEL_CONNECTION_FAILED; | 511 return ERR_TUNNEL_CONNECTION_FAILED; |
511 } | 512 } |
512 } | 513 } |
513 | 514 |
514 int HttpProxyClientSocket::DoDrainBody() { | 515 int HttpProxyClientSocket::DoDrainBody() { |
515 DCHECK(drain_buf_); | 516 DCHECK(drain_buf_); |
516 DCHECK(transport_->is_initialized()); | 517 DCHECK(transport_->is_initialized()); |
517 next_state_ = STATE_DRAIN_BODY_COMPLETE; | 518 next_state_ = STATE_DRAIN_BODY_COMPLETE; |
518 return http_stream_parser_->ReadResponseBody(drain_buf_, kDrainBodyBufferSize, | 519 return http_stream_parser_-> |
519 io_callback_); | 520 ReadResponseBody(drain_buf_.get(), kDrainBodyBufferSize, |
| 521 io_callback_); |
520 } | 522 } |
521 | 523 |
522 int HttpProxyClientSocket::DoDrainBodyComplete(int result) { | 524 int HttpProxyClientSocket::DoDrainBodyComplete(int result) { |
523 if (result < 0) | 525 if (result < 0) |
524 return result; | 526 return result; |
525 | 527 |
526 if (http_stream_parser_->IsResponseBodyComplete()) | 528 if (http_stream_parser_->IsResponseBodyComplete()) |
527 return DidDrainBodyForAuthRestart(true); | 529 return DidDrainBodyForAuthRestart(true); |
528 | 530 |
529 // Keep draining. | 531 // Keep draining. |
530 next_state_ = STATE_DRAIN_BODY; | 532 next_state_ = STATE_DRAIN_BODY; |
531 return OK; | 533 return OK; |
532 } | 534 } |
533 | 535 |
534 int HttpProxyClientSocket::DoTCPRestart() { | 536 int HttpProxyClientSocket::DoTCPRestart() { |
535 next_state_ = STATE_TCP_RESTART_COMPLETE; | 537 next_state_ = STATE_TCP_RESTART_COMPLETE; |
536 return transport_->socket()->Connect( | 538 return transport_->socket()->Connect( |
537 base::Bind(&HttpProxyClientSocket::OnIOComplete, base::Unretained(this))); | 539 base::Bind(&HttpProxyClientSocket::OnIOComplete, base::Unretained(this))); |
538 } | 540 } |
539 | 541 |
540 int HttpProxyClientSocket::DoTCPRestartComplete(int result) { | 542 int HttpProxyClientSocket::DoTCPRestartComplete(int result) { |
541 if (result != OK) | 543 if (result != OK) |
542 return result; | 544 return result; |
543 | 545 |
544 next_state_ = STATE_GENERATE_AUTH_TOKEN; | 546 next_state_ = STATE_GENERATE_AUTH_TOKEN; |
545 return result; | 547 return result; |
546 } | 548 } |
547 | 549 |
548 } // namespace net | 550 } // namespace net |
OLD | NEW |