OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, | 52 request_.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
53 user_agent); | 53 user_agent); |
54 spdy_stream_->SetDelegate(this); | 54 spdy_stream_->SetDelegate(this); |
55 was_ever_used_ = spdy_stream_->WasEverUsed(); | 55 was_ever_used_ = spdy_stream_->WasEverUsed(); |
56 } | 56 } |
57 | 57 |
58 SpdyProxyClientSocket::~SpdyProxyClientSocket() { | 58 SpdyProxyClientSocket::~SpdyProxyClientSocket() { |
59 Disconnect(); | 59 Disconnect(); |
60 } | 60 } |
61 | 61 |
| 62 HttpStream* SpdyProxyClientSocket::CreateConnectResponseStream() { |
| 63 DCHECK(response_stream_.get()); |
| 64 return response_stream_.release(); |
| 65 } |
| 66 |
62 // Sends a SYN_STREAM frame to the proxy with a CONNECT request | 67 // Sends a SYN_STREAM frame to the proxy with a CONNECT request |
63 // for the specified endpoint. Waits for the server to send back | 68 // for the specified endpoint. Waits for the server to send back |
64 // a SYN_REPLY frame. OK will be returned if the status is 200. | 69 // a SYN_REPLY frame. OK will be returned if the status is 200. |
65 // ERR_TUNNEL_CONNECTION_FAILED will be returned for any other status. | 70 // ERR_TUNNEL_CONNECTION_FAILED will be returned for any other status. |
66 // In any of these cases, Read() may be called to retrieve the HTTP | 71 // In any of these cases, Read() may be called to retrieve the HTTP |
67 // response body. Any other return values should be considered fatal. | 72 // response body. Any other return values should be considered fatal. |
68 // TODO(rch): handle 407 proxy auth requested correctly, perhaps | 73 // TODO(rch): handle 407 proxy auth requested correctly, perhaps |
69 // by creating a new stream for the subsequent request. | 74 // by creating a new stream for the subsequent request. |
70 // TODO(rch): create a more appropriate error code to disambiguate | 75 // TODO(rch): create a more appropriate error code to disambiguate |
71 // the HTTPS Proxy tunnel failure from an HTTP Proxy tunnel failure. | 76 // the HTTPS Proxy tunnel failure from an HTTP Proxy tunnel failure. |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) | 351 if (response_.headers->GetParsedHttpVersion() < HttpVersion(1, 0)) |
347 return ERR_TUNNEL_CONNECTION_FAILED; | 352 return ERR_TUNNEL_CONNECTION_FAILED; |
348 | 353 |
349 next_state_ = STATE_OPEN; | 354 next_state_ = STATE_OPEN; |
350 if (net_log_.IsLoggingAllEvents()) { | 355 if (net_log_.IsLoggingAllEvents()) { |
351 net_log_.AddEvent( | 356 net_log_.AddEvent( |
352 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, | 357 NetLog::TYPE_HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
353 make_scoped_refptr(new NetLogHttpResponseParameter(response_.headers))); | 358 make_scoped_refptr(new NetLogHttpResponseParameter(response_.headers))); |
354 } | 359 } |
355 | 360 |
356 if (response_.headers->response_code() == 200) | 361 if (response_.headers->response_code() == 200) { |
357 return OK; | 362 return OK; |
358 else | 363 } else if (response_.headers->response_code() == 407) { |
359 return ERR_TUNNEL_CONNECTION_FAILED; | 364 return ERR_TUNNEL_CONNECTION_FAILED; |
| 365 } else { |
| 366 // Immediately hand off our SpdyStream to a newly created SpdyHttpStream |
| 367 // so that any subsequent SpdyFrames are processed in the context of |
| 368 // the HttpStream, not the socket. |
| 369 DCHECK(spdy_stream_); |
| 370 SpdyStream* stream = spdy_stream_; |
| 371 spdy_stream_ = NULL; |
| 372 response_stream_.reset(new SpdyHttpStream(NULL, false)); |
| 373 response_stream_->InitializeWithExistingStream(stream); |
| 374 next_state_ = STATE_DISCONNECTED; |
| 375 return ERR_HTTPS_PROXY_TUNNEL_RESPONSE; |
| 376 } |
360 } | 377 } |
361 | 378 |
362 // SpdyStream::Delegate methods: | 379 // SpdyStream::Delegate methods: |
363 // Called when SYN frame has been sent. | 380 // Called when SYN frame has been sent. |
364 // Returns true if no more data to be sent after SYN frame. | 381 // Returns true if no more data to be sent after SYN frame. |
365 bool SpdyProxyClientSocket::OnSendHeadersComplete(int status) { | 382 bool SpdyProxyClientSocket::OnSendHeadersComplete(int status) { |
366 DCHECK_EQ(next_state_, STATE_SEND_REQUEST_COMPLETE); | 383 DCHECK_EQ(next_state_, STATE_SEND_REQUEST_COMPLETE); |
367 | 384 |
368 OnIOComplete(status); | 385 OnIOComplete(status); |
369 | 386 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 read_callback->Run(status); | 484 read_callback->Run(status); |
468 } else if (read_callback_) { | 485 } else if (read_callback_) { |
469 // If we have a read_callback, the we need to make sure we call it back | 486 // If we have a read_callback, the we need to make sure we call it back |
470 OnDataReceived(NULL, 0); | 487 OnDataReceived(NULL, 0); |
471 } | 488 } |
472 if (write_callback) | 489 if (write_callback) |
473 write_callback->Run(ERR_CONNECTION_CLOSED); | 490 write_callback->Run(ERR_CONNECTION_CLOSED); |
474 } | 491 } |
475 | 492 |
476 } // namespace net | 493 } // namespace net |
OLD | NEW |