Chromium Code Reviews| 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_network_transaction.h" | 5 #include "net/http/http_network_transaction.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 io_callback_(base::Bind(&HttpNetworkTransaction::OnIOComplete, | 122 io_callback_(base::Bind(&HttpNetworkTransaction::OnIOComplete, |
| 123 base::Unretained(this))), | 123 base::Unretained(this))), |
| 124 session_(session), | 124 session_(session), |
| 125 request_(NULL), | 125 request_(NULL), |
| 126 priority_(priority), | 126 priority_(priority), |
| 127 headers_valid_(false), | 127 headers_valid_(false), |
| 128 logged_response_time_(false), | 128 logged_response_time_(false), |
| 129 request_headers_(), | 129 request_headers_(), |
| 130 read_buf_len_(0), | 130 read_buf_len_(0), |
| 131 next_state_(STATE_NONE), | 131 next_state_(STATE_NONE), |
| 132 establishing_tunnel_(false) { | 132 establishing_tunnel_(false), |
| 133 websocket_handshake_stream_base_factory_(NULL) { | |
| 133 session->ssl_config_service()->GetSSLConfig(&server_ssl_config_); | 134 session->ssl_config_service()->GetSSLConfig(&server_ssl_config_); |
| 134 if (session->http_stream_factory()->has_next_protos()) { | 135 if (session->http_stream_factory()->has_next_protos()) { |
| 135 server_ssl_config_.next_protos = | 136 server_ssl_config_.next_protos = |
| 136 session->http_stream_factory()->next_protos(); | 137 session->http_stream_factory()->next_protos(); |
| 137 } | 138 } |
| 138 proxy_ssl_config_ = server_ssl_config_; | 139 proxy_ssl_config_ = server_ssl_config_; |
| 139 } | 140 } |
| 140 | 141 |
| 141 HttpNetworkTransaction::~HttpNetworkTransaction() { | 142 HttpNetworkTransaction::~HttpNetworkTransaction() { |
| 142 if (stream_.get()) { | 143 if (stream_.get()) { |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 } | 423 } |
| 423 | 424 |
| 424 void HttpNetworkTransaction::SetPriority(RequestPriority priority) { | 425 void HttpNetworkTransaction::SetPriority(RequestPriority priority) { |
| 425 priority_ = priority; | 426 priority_ = priority; |
| 426 if (stream_request_) | 427 if (stream_request_) |
| 427 stream_request_->SetPriority(priority); | 428 stream_request_->SetPriority(priority); |
| 428 if (stream_) | 429 if (stream_) |
| 429 stream_->SetPriority(priority); | 430 stream_->SetPriority(priority); |
| 430 } | 431 } |
| 431 | 432 |
| 433 void HttpNetworkTransaction::SetWebSocketHandshakeStreamFactory( | |
| 434 WebSocketHandshakeStreamBase::Factory* factory) { | |
| 435 websocket_handshake_stream_base_factory_ = factory; | |
| 436 } | |
| 437 | |
| 432 void HttpNetworkTransaction::OnStreamReady(const SSLConfig& used_ssl_config, | 438 void HttpNetworkTransaction::OnStreamReady(const SSLConfig& used_ssl_config, |
| 433 const ProxyInfo& used_proxy_info, | 439 const ProxyInfo& used_proxy_info, |
| 434 HttpStreamBase* stream) { | 440 HttpStreamBase* stream) { |
| 435 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); | 441 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); |
| 436 DCHECK(stream_request_.get()); | 442 DCHECK(stream_request_.get()); |
| 437 | 443 |
| 438 stream_.reset(stream); | 444 stream_.reset(stream); |
| 439 server_ssl_config_ = used_ssl_config; | 445 server_ssl_config_ = used_ssl_config; |
| 440 proxy_info_ = used_proxy_info; | 446 proxy_info_ = used_proxy_info; |
| 441 response_.was_npn_negotiated = stream_request_->was_npn_negotiated(); | 447 response_.was_npn_negotiated = stream_request_->was_npn_negotiated(); |
| 442 response_.npn_negotiated_protocol = SSLClientSocket::NextProtoToString( | 448 response_.npn_negotiated_protocol = SSLClientSocket::NextProtoToString( |
| 443 stream_request_->protocol_negotiated()); | 449 stream_request_->protocol_negotiated()); |
| 444 response_.was_fetched_via_spdy = stream_request_->using_spdy(); | 450 response_.was_fetched_via_spdy = stream_request_->using_spdy(); |
| 445 response_.was_fetched_via_proxy = !proxy_info_.is_direct(); | 451 response_.was_fetched_via_proxy = !proxy_info_.is_direct(); |
| 446 | 452 |
| 447 OnIOComplete(OK); | 453 OnIOComplete(OK); |
| 448 } | 454 } |
| 449 | 455 |
| 450 void HttpNetworkTransaction::OnWebSocketHandshakeStreamReady( | 456 void HttpNetworkTransaction::OnWebSocketHandshakeStreamReady( |
| 451 const SSLConfig& used_ssl_config, | 457 const SSLConfig& used_ssl_config, |
| 452 const ProxyInfo& used_proxy_info, | 458 const ProxyInfo& used_proxy_info, |
| 453 WebSocketHandshakeStreamBase* stream) { | 459 WebSocketHandshakeStreamBase* stream) { |
| 454 NOTREACHED() << "This function should never be called."; | 460 OnStreamReady(used_ssl_config, used_proxy_info, stream); |
| 455 } | 461 } |
| 456 | 462 |
| 457 void HttpNetworkTransaction::OnStreamFailed(int result, | 463 void HttpNetworkTransaction::OnStreamFailed(int result, |
| 458 const SSLConfig& used_ssl_config) { | 464 const SSLConfig& used_ssl_config) { |
| 459 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); | 465 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); |
| 460 DCHECK_NE(OK, result); | 466 DCHECK_NE(OK, result); |
| 461 DCHECK(stream_request_.get()); | 467 DCHECK(stream_request_.get()); |
| 462 DCHECK(!stream_.get()); | 468 DCHECK(!stream_.get()); |
| 463 server_ssl_config_ = used_ssl_config; | 469 server_ssl_config_ = used_ssl_config; |
| 464 | 470 |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 650 break; | 656 break; |
| 651 } | 657 } |
| 652 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 658 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 653 | 659 |
| 654 return rv; | 660 return rv; |
| 655 } | 661 } |
| 656 | 662 |
| 657 int HttpNetworkTransaction::DoCreateStream() { | 663 int HttpNetworkTransaction::DoCreateStream() { |
| 658 next_state_ = STATE_CREATE_STREAM_COMPLETE; | 664 next_state_ = STATE_CREATE_STREAM_COMPLETE; |
| 659 | 665 |
| 660 stream_request_.reset( | 666 if (websocket_handshake_stream_base_factory_ && |
| 661 session_->http_stream_factory()->RequestStream( | 667 (request_->url.SchemeIs("ws") || request_->url.SchemeIs("wss"))) { |
| 662 *request_, | 668 stream_request_.reset(session_->websocket_handshake_stream_factory() |
| 663 priority_, | 669 ->RequestWebSocketHandshakeStream( |
| 664 server_ssl_config_, | 670 *request_, |
| 665 proxy_ssl_config_, | 671 priority_, |
| 666 this, | 672 server_ssl_config_, |
| 667 net_log_)); | 673 proxy_ssl_config_, |
| 674 this, | |
| 675 websocket_handshake_stream_base_factory_, | |
| 676 net_log_)); | |
| 677 } else { | |
| 678 stream_request_.reset( | |
| 679 session_->http_stream_factory()->RequestStream( | |
| 680 *request_, | |
| 681 priority_, | |
| 682 server_ssl_config_, | |
| 683 proxy_ssl_config_, | |
| 684 this, | |
| 685 net_log_)); | |
| 686 } | |
| 668 DCHECK(stream_request_.get()); | 687 DCHECK(stream_request_.get()); |
| 669 return ERR_IO_PENDING; | 688 return ERR_IO_PENDING; |
| 670 } | 689 } |
| 671 | 690 |
| 672 int HttpNetworkTransaction::DoCreateStreamComplete(int result) { | 691 int HttpNetworkTransaction::DoCreateStreamComplete(int result) { |
| 673 if (result == OK) { | 692 if (result == OK) { |
| 674 next_state_ = STATE_INIT_STREAM; | 693 next_state_ = STATE_INIT_STREAM; |
| 675 DCHECK(stream_.get()); | 694 DCHECK(stream_.get()); |
| 676 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 695 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
| 677 result = HandleCertificateRequest(result); | 696 result = HandleCertificateRequest(result); |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 982 // https://bugzilla.mozilla.org/show_bug.cgi?id=193921 | 1001 // https://bugzilla.mozilla.org/show_bug.cgi?id=193921 |
| 983 if (request_->method == "PUT") | 1002 if (request_->method == "PUT") |
| 984 return ERR_METHOD_NOT_SUPPORTED; | 1003 return ERR_METHOD_NOT_SUPPORTED; |
| 985 } | 1004 } |
| 986 | 1005 |
| 987 // Check for an intermediate 100 Continue response. An origin server is | 1006 // Check for an intermediate 100 Continue response. An origin server is |
| 988 // allowed to send this response even if we didn't ask for it, so we just | 1007 // allowed to send this response even if we didn't ask for it, so we just |
| 989 // need to skip over it. | 1008 // need to skip over it. |
| 990 // We treat any other 1xx in this same way (although in practice getting | 1009 // We treat any other 1xx in this same way (although in practice getting |
| 991 // a 1xx that isn't a 100 is rare). | 1010 // a 1xx that isn't a 100 is rare). |
| 992 if (response_.headers->response_code() / 100 == 1) { | 1011 // Unless this is a WebSocket request, in which case we pass it on up. |
| 1012 if (response_.headers->response_code() / 100 == 1 && | |
| 1013 !websocket_handshake_stream_base_factory_) { | |
|
yhirano
2013/11/06 05:00:05
Code in DoCreateStream does:
if websocket_handsh
Adam Rice
2013/11/07 01:45:22
I tried factoring out the code into a ForWebSocket
| |
| 993 response_.headers = new HttpResponseHeaders(std::string()); | 1014 response_.headers = new HttpResponseHeaders(std::string()); |
| 994 next_state_ = STATE_READ_HEADERS; | 1015 next_state_ = STATE_READ_HEADERS; |
| 995 return OK; | 1016 return OK; |
| 996 } | 1017 } |
| 997 | 1018 |
| 998 HostPortPair endpoint = HostPortPair(request_->url.HostNoBrackets(), | 1019 HostPortPair endpoint = HostPortPair(request_->url.HostNoBrackets(), |
| 999 request_->url.EffectiveIntPort()); | 1020 request_->url.EffectiveIntPort()); |
| 1000 ProcessAlternateProtocol(session_->http_stream_factory(), | 1021 ProcessAlternateProtocol(session_->http_stream_factory(), |
| 1001 session_->http_server_properties(), | 1022 session_->http_server_properties(), |
| 1002 *response_.headers.get(), | 1023 *response_.headers.get(), |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1503 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, | 1524 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
| 1504 state); | 1525 state); |
| 1505 break; | 1526 break; |
| 1506 } | 1527 } |
| 1507 return description; | 1528 return description; |
| 1508 } | 1529 } |
| 1509 | 1530 |
| 1510 #undef STATE_CASE | 1531 #undef STATE_CASE |
| 1511 | 1532 |
| 1512 } // namespace net | 1533 } // namespace net |
| OLD | NEW |