| 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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 // HttpProxyClientSocket. | 316 // HttpProxyClientSocket. |
| 317 net_log_.BeginEvent( | 317 net_log_.BeginEvent( |
| 318 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS); | 318 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS); |
| 319 } | 319 } |
| 320 break; | 320 break; |
| 321 case STATE_READ_REPLY_COMPLETE: | 321 case STATE_READ_REPLY_COMPLETE: |
| 322 rv = DoReadReplyComplete(rv); | 322 rv = DoReadReplyComplete(rv); |
| 323 net_log_.EndEventWithNetErrorCode( | 323 net_log_.EndEventWithNetErrorCode( |
| 324 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS, rv); | 324 NetLog::TYPE_HTTP_TRANSACTION_TUNNEL_READ_HEADERS, rv); |
| 325 break; | 325 break; |
| 326 case STATE_HANDLE_PROXY_AUTH_CHALLENGE: |
| 327 rv = DoHandleProxyAuthChallenge(); |
| 328 break; |
| 329 case STATE_HANDLE_PROXY_AUTH_CHALLENGE_COMPLETE: |
| 330 rv = DoHandleProxyAuthChallengeComplete(rv); |
| 331 break; |
| 326 default: | 332 default: |
| 327 NOTREACHED() << "bad state"; | 333 NOTREACHED() << "bad state"; |
| 328 rv = ERR_UNEXPECTED; | 334 rv = ERR_UNEXPECTED; |
| 329 break; | 335 break; |
| 330 } | 336 } |
| 331 } while (rv != ERR_IO_PENDING && next_state_ != STATE_DISCONNECTED && | 337 } while (rv != ERR_IO_PENDING && next_state_ != STATE_DISCONNECTED && |
| 332 next_state_ != STATE_OPEN); | 338 next_state_ != STATE_OPEN); |
| 333 return rv; | 339 return rv; |
| 334 } | 340 } |
| 335 | 341 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 } | 419 } |
| 414 | 420 |
| 415 redirect_has_load_timing_info_ = | 421 redirect_has_load_timing_info_ = |
| 416 spdy_stream_->GetLoadTimingInfo(&redirect_load_timing_info_); | 422 spdy_stream_->GetLoadTimingInfo(&redirect_load_timing_info_); |
| 417 // Note that this triggers a RST_STREAM_CANCEL. | 423 // Note that this triggers a RST_STREAM_CANCEL. |
| 418 spdy_stream_->DetachDelegate(); | 424 spdy_stream_->DetachDelegate(); |
| 419 next_state_ = STATE_DISCONNECTED; | 425 next_state_ = STATE_DISCONNECTED; |
| 420 return ERR_HTTPS_PROXY_TUNNEL_RESPONSE; | 426 return ERR_HTTPS_PROXY_TUNNEL_RESPONSE; |
| 421 | 427 |
| 422 case 407: // Proxy Authentication Required | 428 case 407: // Proxy Authentication Required |
| 423 next_state_ = STATE_OPEN; | 429 next_state_ = STATE_HANDLE_PROXY_AUTH_CHALLENGE; |
| 424 if (!SanitizeProxyAuth(&response_)) { | 430 return OK; |
| 425 LogBlockedTunnelResponse(); | |
| 426 return ERR_TUNNEL_CONNECTION_FAILED; | |
| 427 } | |
| 428 return HandleProxyAuthChallenge(auth_.get(), &response_, net_log_); | |
| 429 | 431 |
| 430 default: | 432 default: |
| 431 // Ignore response to avoid letting the proxy impersonate the target | 433 // Ignore response to avoid letting the proxy impersonate the target |
| 432 // server. (See http://crbug.com/137891.) | 434 // server. (See http://crbug.com/137891.) |
| 433 LogBlockedTunnelResponse(); | 435 LogBlockedTunnelResponse(); |
| 434 return ERR_TUNNEL_CONNECTION_FAILED; | 436 return ERR_TUNNEL_CONNECTION_FAILED; |
| 435 } | 437 } |
| 436 } | 438 } |
| 437 | 439 |
| 440 int SpdyProxyClientSocket::DoHandleProxyAuthChallenge() { |
| 441 if (!SanitizeProxyAuth(&response_)) { |
| 442 LogBlockedTunnelResponse(); |
| 443 return ERR_TUNNEL_CONNECTION_FAILED; |
| 444 } |
| 445 next_state_ = STATE_HANDLE_PROXY_AUTH_CHALLENGE_COMPLETE; |
| 446 return auth_->HandleAuthChallenge( |
| 447 response_, base::Bind(&SpdyProxyClientSocket::OnIOComplete, |
| 448 weak_factory_.GetWeakPtr()), |
| 449 net_log_); |
| 450 } |
| 451 |
| 452 int SpdyProxyClientSocket::DoHandleProxyAuthChallengeComplete(int result) { |
| 453 next_state_ = STATE_OPEN; |
| 454 if (result != OK) |
| 455 return result; |
| 456 if (auth_->HaveAuthHandler()) { |
| 457 response_.auth_challenge = auth_->auth_info(); |
| 458 return ERR_PROXY_AUTH_REQUESTED; |
| 459 } |
| 460 return ERR_PROXY_AUTH_UNSUPPORTED; |
| 461 } |
| 462 |
| 438 // SpdyStream::Delegate methods: | 463 // SpdyStream::Delegate methods: |
| 439 // Called when SYN frame has been sent. | 464 // Called when SYN frame has been sent. |
| 440 // Returns true if no more data to be sent after SYN frame. | 465 // Returns true if no more data to be sent after SYN frame. |
| 441 void SpdyProxyClientSocket::OnRequestHeadersSent() { | 466 void SpdyProxyClientSocket::OnRequestHeadersSent() { |
| 442 DCHECK_EQ(next_state_, STATE_SEND_REQUEST_COMPLETE); | 467 DCHECK_EQ(next_state_, STATE_SEND_REQUEST_COMPLETE); |
| 443 | 468 |
| 444 OnIOComplete(OK); | 469 OnIOComplete(OK); |
| 445 } | 470 } |
| 446 | 471 |
| 447 SpdyResponseHeadersStatus SpdyProxyClientSocket::OnResponseHeadersUpdated( | 472 SpdyResponseHeadersStatus SpdyProxyClientSocket::OnResponseHeadersUpdated( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } else if (!read_callback_.is_null()) { | 553 } else if (!read_callback_.is_null()) { |
| 529 // If we have a read_callback_, the we need to make sure we call it back. | 554 // If we have a read_callback_, the we need to make sure we call it back. |
| 530 OnDataReceived(scoped_ptr<SpdyBuffer>()); | 555 OnDataReceived(scoped_ptr<SpdyBuffer>()); |
| 531 } | 556 } |
| 532 // This may have been deleted by read_callback_, so check first. | 557 // This may have been deleted by read_callback_, so check first. |
| 533 if (weak_ptr.get() && !write_callback.is_null()) | 558 if (weak_ptr.get() && !write_callback.is_null()) |
| 534 write_callback.Run(ERR_CONNECTION_CLOSED); | 559 write_callback.Run(ERR_CONNECTION_CLOSED); |
| 535 } | 560 } |
| 536 | 561 |
| 537 } // namespace net | 562 } // namespace net |
| OLD | NEW |