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 (ForWebSocketHandshake()) { |
661 session_->http_stream_factory()->RequestStream( | 667 stream_request_.reset(session_->websocket_handshake_stream_factory() |
662 *request_, | 668 ->RequestWebSocketHandshakeStream( |
663 priority_, | 669 *request_, |
664 server_ssl_config_, | 670 priority_, |
665 proxy_ssl_config_, | 671 server_ssl_config_, |
666 this, | 672 proxy_ssl_config_, |
667 net_log_)); | 673 this, |
| 674 websocket_handshake_stream_base_factory_, |
| 675 net_log_)); |
| 676 } else { |
| 677 stream_request_.reset( |
| 678 session_->http_stream_factory()->RequestStream( |
| 679 *request_, |
| 680 priority_, |
| 681 server_ssl_config_, |
| 682 proxy_ssl_config_, |
| 683 this, |
| 684 net_log_)); |
| 685 } |
668 DCHECK(stream_request_.get()); | 686 DCHECK(stream_request_.get()); |
669 return ERR_IO_PENDING; | 687 return ERR_IO_PENDING; |
670 } | 688 } |
671 | 689 |
672 int HttpNetworkTransaction::DoCreateStreamComplete(int result) { | 690 int HttpNetworkTransaction::DoCreateStreamComplete(int result) { |
673 if (result == OK) { | 691 if (result == OK) { |
674 next_state_ = STATE_INIT_STREAM; | 692 next_state_ = STATE_INIT_STREAM; |
675 DCHECK(stream_.get()); | 693 DCHECK(stream_.get()); |
676 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { | 694 } else if (result == ERR_SSL_CLIENT_AUTH_CERT_NEEDED) { |
677 result = HandleCertificateRequest(result); | 695 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 | 1000 // https://bugzilla.mozilla.org/show_bug.cgi?id=193921 |
983 if (request_->method == "PUT") | 1001 if (request_->method == "PUT") |
984 return ERR_METHOD_NOT_SUPPORTED; | 1002 return ERR_METHOD_NOT_SUPPORTED; |
985 } | 1003 } |
986 | 1004 |
987 // Check for an intermediate 100 Continue response. An origin server is | 1005 // 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 | 1006 // allowed to send this response even if we didn't ask for it, so we just |
989 // need to skip over it. | 1007 // need to skip over it. |
990 // We treat any other 1xx in this same way (although in practice getting | 1008 // We treat any other 1xx in this same way (although in practice getting |
991 // a 1xx that isn't a 100 is rare). | 1009 // a 1xx that isn't a 100 is rare). |
992 if (response_.headers->response_code() / 100 == 1) { | 1010 // Unless this is a WebSocket request, in which case we pass it on up. |
| 1011 if (response_.headers->response_code() / 100 == 1 && |
| 1012 !ForWebSocketHandshake()) { |
993 response_.headers = new HttpResponseHeaders(std::string()); | 1013 response_.headers = new HttpResponseHeaders(std::string()); |
994 next_state_ = STATE_READ_HEADERS; | 1014 next_state_ = STATE_READ_HEADERS; |
995 return OK; | 1015 return OK; |
996 } | 1016 } |
997 | 1017 |
998 HostPortPair endpoint = HostPortPair(request_->url.HostNoBrackets(), | 1018 HostPortPair endpoint = HostPortPair(request_->url.HostNoBrackets(), |
999 request_->url.EffectiveIntPort()); | 1019 request_->url.EffectiveIntPort()); |
1000 ProcessAlternateProtocol(session_->http_stream_factory(), | 1020 ProcessAlternateProtocol(session_->http_stream_factory(), |
1001 session_->http_server_properties(), | 1021 session_->http_server_properties(), |
1002 *response_.headers.get(), | 1022 *response_.headers.get(), |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 return GURL(scheme + | 1489 return GURL(scheme + |
1470 proxy_info_.proxy_server().host_port_pair().ToString()); | 1490 proxy_info_.proxy_server().host_port_pair().ToString()); |
1471 } | 1491 } |
1472 case HttpAuth::AUTH_SERVER: | 1492 case HttpAuth::AUTH_SERVER: |
1473 return request_->url; | 1493 return request_->url; |
1474 default: | 1494 default: |
1475 return GURL(); | 1495 return GURL(); |
1476 } | 1496 } |
1477 } | 1497 } |
1478 | 1498 |
| 1499 bool HttpNetworkTransaction::ForWebSocketHandshake() const { |
| 1500 return (websocket_handshake_stream_base_factory_ && |
| 1501 (request_->url.SchemeIs("ws") || request_->url.SchemeIs("wss"))); |
| 1502 } |
| 1503 |
1479 #define STATE_CASE(s) \ | 1504 #define STATE_CASE(s) \ |
1480 case s: \ | 1505 case s: \ |
1481 description = base::StringPrintf("%s (0x%08X)", #s, s); \ | 1506 description = base::StringPrintf("%s (0x%08X)", #s, s); \ |
1482 break | 1507 break |
1483 | 1508 |
1484 std::string HttpNetworkTransaction::DescribeState(State state) { | 1509 std::string HttpNetworkTransaction::DescribeState(State state) { |
1485 std::string description; | 1510 std::string description; |
1486 switch (state) { | 1511 switch (state) { |
1487 STATE_CASE(STATE_CREATE_STREAM); | 1512 STATE_CASE(STATE_CREATE_STREAM); |
1488 STATE_CASE(STATE_CREATE_STREAM_COMPLETE); | 1513 STATE_CASE(STATE_CREATE_STREAM_COMPLETE); |
(...skipping 14 matching lines...) Expand all Loading... |
1503 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, | 1528 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
1504 state); | 1529 state); |
1505 break; | 1530 break; |
1506 } | 1531 } |
1507 return description; | 1532 return description; |
1508 } | 1533 } |
1509 | 1534 |
1510 #undef STATE_CASE | 1535 #undef STATE_CASE |
1511 | 1536 |
1512 } // namespace net | 1537 } // namespace net |
OLD | NEW |