Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: net/http/http_network_transaction.cc

Issue 2771263002: Retry upon 421 status code without IP pooling. (Closed)
Patch Set: Rebase. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_network_transaction.h ('k') | net/http/http_network_transaction_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 session_(session), 93 session_(session),
94 request_(NULL), 94 request_(NULL),
95 priority_(priority), 95 priority_(priority),
96 headers_valid_(false), 96 headers_valid_(false),
97 request_headers_(), 97 request_headers_(),
98 read_buf_len_(0), 98 read_buf_len_(0),
99 total_received_bytes_(0), 99 total_received_bytes_(0),
100 total_sent_bytes_(0), 100 total_sent_bytes_(0),
101 next_state_(STATE_NONE), 101 next_state_(STATE_NONE),
102 establishing_tunnel_(false), 102 establishing_tunnel_(false),
103 enable_ip_based_pooling_(true),
103 websocket_handshake_stream_base_create_helper_(NULL), 104 websocket_handshake_stream_base_create_helper_(NULL),
104 net_error_details_() { 105 net_error_details_() {}
105 }
106 106
107 HttpNetworkTransaction::~HttpNetworkTransaction() { 107 HttpNetworkTransaction::~HttpNetworkTransaction() {
108 if (stream_.get()) { 108 if (stream_.get()) {
109 // TODO(mbelshe): The stream_ should be able to compute whether or not the 109 // TODO(mbelshe): The stream_ should be able to compute whether or not the
110 // stream should be kept alive. No reason to compute here 110 // stream should be kept alive. No reason to compute here
111 // and pass it in. 111 // and pass it in.
112 if (!stream_->CanReuseConnection() || next_state_ != STATE_NONE) { 112 if (!stream_->CanReuseConnection() || next_state_ != STATE_NONE) {
113 stream_->Close(true /* not reusable */); 113 stream_->Close(true /* not reusable */);
114 } else if (stream_->IsResponseBodyComplete()) { 114 } else if (stream_->IsResponseBodyComplete()) {
115 // If the response body is complete, we can just reuse the socket. 115 // If the response body is complete, we can just reuse the socket.
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 FROM_HERE_WITH_EXPLICIT_FUNCTION( 840 FROM_HERE_WITH_EXPLICIT_FUNCTION(
841 "424359 HttpNetworkTransaction::DoCreateStream")); 841 "424359 HttpNetworkTransaction::DoCreateStream"));
842 842
843 response_.network_accessed = true; 843 response_.network_accessed = true;
844 844
845 next_state_ = STATE_CREATE_STREAM_COMPLETE; 845 next_state_ = STATE_CREATE_STREAM_COMPLETE;
846 if (ForWebSocketHandshake()) { 846 if (ForWebSocketHandshake()) {
847 stream_request_.reset( 847 stream_request_.reset(
848 session_->http_stream_factory_for_websocket() 848 session_->http_stream_factory_for_websocket()
849 ->RequestWebSocketHandshakeStream( 849 ->RequestWebSocketHandshakeStream(
850 *request_, 850 *request_, priority_, server_ssl_config_, proxy_ssl_config_,
851 priority_, 851 this, websocket_handshake_stream_base_create_helper_,
852 server_ssl_config_, 852 enable_ip_based_pooling_, net_log_));
853 proxy_ssl_config_,
854 this,
855 websocket_handshake_stream_base_create_helper_,
856 net_log_));
857 } else { 853 } else {
858 stream_request_.reset( 854 stream_request_.reset(session_->http_stream_factory()->RequestStream(
859 session_->http_stream_factory()->RequestStream( 855 *request_, priority_, server_ssl_config_, proxy_ssl_config_, this,
860 *request_, 856 enable_ip_based_pooling_, net_log_));
861 priority_,
862 server_ssl_config_,
863 proxy_ssl_config_,
864 this,
865 net_log_));
866 } 857 }
867 DCHECK(stream_request_.get()); 858 DCHECK(stream_request_.get());
868 return ERR_IO_PENDING; 859 return ERR_IO_PENDING;
869 } 860 }
870 861
871 int HttpNetworkTransaction::DoCreateStreamComplete(int result) { 862 int HttpNetworkTransaction::DoCreateStreamComplete(int result) {
872 // If |result| is ERR_HTTPS_PROXY_TUNNEL_RESPONSE, then 863 // If |result| is ERR_HTTPS_PROXY_TUNNEL_RESPONSE, then
873 // DoCreateStreamComplete is being called from OnHttpsProxyTunnelResponse, 864 // DoCreateStreamComplete is being called from OnHttpsProxyTunnelResponse,
874 // which resets the stream request first. Therefore, we have to grab the 865 // which resets the stream request first. Therefore, we have to grab the
875 // connection attempts in *that* function instead of here in that case. 866 // connection attempts in *that* function instead of here in that case.
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 // We treat any other 1xx in this same way (although in practice getting 1276 // We treat any other 1xx in this same way (although in practice getting
1286 // a 1xx that isn't a 100 is rare). 1277 // a 1xx that isn't a 100 is rare).
1287 // Unless this is a WebSocket request, in which case we pass it on up. 1278 // Unless this is a WebSocket request, in which case we pass it on up.
1288 if (response_.headers->response_code() / 100 == 1 && 1279 if (response_.headers->response_code() / 100 == 1 &&
1289 !ForWebSocketHandshake()) { 1280 !ForWebSocketHandshake()) {
1290 response_.headers = new HttpResponseHeaders(std::string()); 1281 response_.headers = new HttpResponseHeaders(std::string());
1291 next_state_ = STATE_READ_HEADERS; 1282 next_state_ = STATE_READ_HEADERS;
1292 return OK; 1283 return OK;
1293 } 1284 }
1294 1285
1286 if (response_.headers->response_code() == 421) {
1287 return HandleIOError(ERR_MISDIRECTED_REQUEST);
1288 }
1289
1295 if (IsSecureRequest()) { 1290 if (IsSecureRequest()) {
1296 session_->http_stream_factory()->ProcessAlternativeServices( 1291 session_->http_stream_factory()->ProcessAlternativeServices(
1297 session_, response_.headers.get(), url::SchemeHostPort(request_->url)); 1292 session_, response_.headers.get(), url::SchemeHostPort(request_->url));
1298 } 1293 }
1299 1294
1300 if (IsSecureRequest()) 1295 if (IsSecureRequest())
1301 stream_->GetSSLInfo(&response_.ssl_info); 1296 stream_->GetSSLInfo(&response_.ssl_info);
1302 1297
1303 int rv = HandleAuthChallenge(); 1298 int rv = HandleAuthChallenge();
1304 if (rv != OK) 1299 if (rv != OK)
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 } 1534 }
1540 break; 1535 break;
1541 case ERR_SPDY_PING_FAILED: 1536 case ERR_SPDY_PING_FAILED:
1542 case ERR_SPDY_SERVER_REFUSED_STREAM: 1537 case ERR_SPDY_SERVER_REFUSED_STREAM:
1543 case ERR_QUIC_HANDSHAKE_FAILED: 1538 case ERR_QUIC_HANDSHAKE_FAILED:
1544 net_log_.AddEventWithNetErrorCode( 1539 net_log_.AddEventWithNetErrorCode(
1545 NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR, error); 1540 NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR, error);
1546 ResetConnectionAndRequestForResend(); 1541 ResetConnectionAndRequestForResend();
1547 error = OK; 1542 error = OK;
1548 break; 1543 break;
1544 case ERR_MISDIRECTED_REQUEST:
Ryan Hamilton 2017/03/30 23:51:07 It's a bit weird that ERR_MISDIRECTED_REQUEST is a
Bence 2017/03/31 00:09:33 Yes, I absolutely agree with you. I was thinking
1545 // If this is the second try, just give up.
1546 if (!enable_ip_based_pooling_)
1547 return OK;
1548 // Otherwise, since the response status was 421 Misdirected Request,
1549 // retry the request with IP based pooling disabled.
1550 enable_ip_based_pooling_ = false;
1551 net_log_.AddEventWithNetErrorCode(
1552 NetLogEventType::HTTP_TRANSACTION_RESTART_AFTER_ERROR, error);
1553 ResetConnectionAndRequestForResend();
1554 error = OK;
1555 break;
1549 } 1556 }
1550 return error; 1557 return error;
1551 } 1558 }
1552 1559
1553 void HttpNetworkTransaction::ResetStateForRestart() { 1560 void HttpNetworkTransaction::ResetStateForRestart() {
1554 ResetStateForAuthRestart(); 1561 ResetStateForAuthRestart();
1555 if (stream_) { 1562 if (stream_) {
1556 total_received_bytes_ += stream_->GetTotalReceivedBytes(); 1563 total_received_bytes_ += stream_->GetTotalReceivedBytes();
1557 total_sent_bytes_ += stream_->GetTotalSentBytes(); 1564 total_sent_bytes_ += stream_->GetTotalSentBytes();
1558 } 1565 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 DCHECK(stream_request_); 1712 DCHECK(stream_request_);
1706 1713
1707 // Since the transaction can restart with auth credentials, it may create a 1714 // Since the transaction can restart with auth credentials, it may create a
1708 // stream more than once. Accumulate all of the connection attempts across 1715 // stream more than once. Accumulate all of the connection attempts across
1709 // those streams by appending them to the vector: 1716 // those streams by appending them to the vector:
1710 for (const auto& attempt : stream_request_->connection_attempts()) 1717 for (const auto& attempt : stream_request_->connection_attempts())
1711 connection_attempts_.push_back(attempt); 1718 connection_attempts_.push_back(attempt);
1712 } 1719 }
1713 1720
1714 } // namespace net 1721 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.h ('k') | net/http/http_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698