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

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

Issue 2771263002: Retry upon 421 status code without IP pooling. (Closed)
Patch Set: Created 3 years, 9 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
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_stream_factory_impl_job.h" 5 #include "net/http/http_stream_factory_impl_job.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 HttpStreamFactoryImpl::Job::Job(Delegate* delegate, 164 HttpStreamFactoryImpl::Job::Job(Delegate* delegate,
165 JobType job_type, 165 JobType job_type,
166 HttpNetworkSession* session, 166 HttpNetworkSession* session,
167 const HttpRequestInfo& request_info, 167 const HttpRequestInfo& request_info,
168 RequestPriority priority, 168 RequestPriority priority,
169 const SSLConfig& server_ssl_config, 169 const SSLConfig& server_ssl_config,
170 const SSLConfig& proxy_ssl_config, 170 const SSLConfig& proxy_ssl_config,
171 HostPortPair destination, 171 HostPortPair destination,
172 GURL origin_url, 172 GURL origin_url,
173 bool enable_ip_based_pooling,
173 NetLog* net_log) 174 NetLog* net_log)
174 : Job(delegate, 175 : Job(delegate,
175 job_type, 176 job_type,
176 session, 177 session,
177 request_info, 178 request_info,
178 priority, 179 priority,
179 server_ssl_config, 180 server_ssl_config,
180 proxy_ssl_config, 181 proxy_ssl_config,
181 destination, 182 destination,
182 origin_url, 183 origin_url,
183 AlternativeService(), 184 AlternativeService(),
184 ProxyServer(), 185 ProxyServer(),
186 enable_ip_based_pooling,
185 net_log) {} 187 net_log) {}
186 188
187 HttpStreamFactoryImpl::Job::Job(Delegate* delegate, 189 HttpStreamFactoryImpl::Job::Job(Delegate* delegate,
188 JobType job_type, 190 JobType job_type,
189 HttpNetworkSession* session, 191 HttpNetworkSession* session,
190 const HttpRequestInfo& request_info, 192 const HttpRequestInfo& request_info,
191 RequestPriority priority, 193 RequestPriority priority,
192 const SSLConfig& server_ssl_config, 194 const SSLConfig& server_ssl_config,
193 const SSLConfig& proxy_ssl_config, 195 const SSLConfig& proxy_ssl_config,
194 HostPortPair destination, 196 HostPortPair destination,
195 GURL origin_url, 197 GURL origin_url,
196 AlternativeService alternative_service, 198 AlternativeService alternative_service,
197 const ProxyServer& alternative_proxy_server, 199 const ProxyServer& alternative_proxy_server,
200 bool enable_ip_based_pooling,
198 NetLog* net_log) 201 NetLog* net_log)
199 : request_info_(request_info), 202 : request_info_(request_info),
200 priority_(priority), 203 priority_(priority),
201 server_ssl_config_(server_ssl_config), 204 server_ssl_config_(server_ssl_config),
202 proxy_ssl_config_(proxy_ssl_config), 205 proxy_ssl_config_(proxy_ssl_config),
203 net_log_( 206 net_log_(
204 NetLogWithSource::Make(net_log, NetLogSourceType::HTTP_STREAM_JOB)), 207 NetLogWithSource::Make(net_log, NetLogSourceType::HTTP_STREAM_JOB)),
205 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))), 208 io_callback_(base::Bind(&Job::OnIOComplete, base::Unretained(this))),
206 connection_(new ClientSocketHandle), 209 connection_(new ClientSocketHandle),
207 session_(session), 210 session_(session),
208 next_state_(STATE_NONE), 211 next_state_(STATE_NONE),
209 pac_request_(NULL), 212 pac_request_(NULL),
210 destination_(destination), 213 destination_(destination),
211 origin_url_(origin_url), 214 origin_url_(origin_url),
212 alternative_service_(alternative_service), 215 alternative_service_(alternative_service),
213 alternative_proxy_server_(alternative_proxy_server), 216 alternative_proxy_server_(alternative_proxy_server),
217 enable_ip_based_pooling_(enable_ip_based_pooling),
214 delegate_(delegate), 218 delegate_(delegate),
215 job_type_(job_type), 219 job_type_(job_type),
216 using_ssl_(false), 220 using_ssl_(false),
217 using_spdy_(false), 221 using_spdy_(false),
218 using_quic_(false), 222 using_quic_(false),
219 quic_request_(session_->quic_stream_factory()), 223 quic_request_(session_->quic_stream_factory()),
220 using_existing_quic_session_(false), 224 using_existing_quic_session_(false),
221 establishing_tunnel_(false), 225 establishing_tunnel_(false),
222 was_alpn_negotiated_(false), 226 was_alpn_negotiated_(false),
223 negotiated_protocol_(kProtoUnknown), 227 negotiated_protocol_(kProtoUnknown),
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 } 533 }
530 delegate_->OnPreconnectsComplete(this); 534 delegate_->OnPreconnectsComplete(this);
531 // |this| may be deleted after this call. 535 // |this| may be deleted after this call.
532 } 536 }
533 537
534 // static 538 // static
535 int HttpStreamFactoryImpl::Job::OnHostResolution( 539 int HttpStreamFactoryImpl::Job::OnHostResolution(
536 SpdySessionPool* spdy_session_pool, 540 SpdySessionPool* spdy_session_pool,
537 const SpdySessionKey& spdy_session_key, 541 const SpdySessionKey& spdy_session_key,
538 const GURL& origin_url, 542 const GURL& origin_url,
543 bool enable_ip_based_pooling,
539 const AddressList& addresses, 544 const AddressList& addresses,
540 const NetLogWithSource& net_log) { 545 const NetLogWithSource& net_log) {
541 // It is OK to dereference spdy_session_pool, because the 546 // It is OK to dereference spdy_session_pool, because the
542 // ClientSocketPoolManager will be destroyed in the same callback that 547 // ClientSocketPoolManager will be destroyed in the same callback that
543 // destroys the SpdySessionPool. 548 // destroys the SpdySessionPool.
544 return spdy_session_pool->FindAvailableSession( 549 return spdy_session_pool->FindAvailableSession(
545 spdy_session_key, origin_url, /* enable_ip_based_pooling = */ true, 550 spdy_session_key, origin_url, enable_ip_based_pooling, net_log)
Zhongyi Shi 2017/03/29 03:05:06 I thought we could just use the enable_ip_based_po
Bence 2017/03/29 16:46:08 Yes, this method is static. That's why |spdy_sess
Zhongyi Shi 2017/03/30 22:33:02 Acknowledged. I see, I didn't realize it's a stati
546 net_log)
547 ? ERR_SPDY_SESSION_ALREADY_EXISTS 551 ? ERR_SPDY_SESSION_ALREADY_EXISTS
548 : OK; 552 : OK;
549 } 553 }
550 554
551 void HttpStreamFactoryImpl::Job::OnIOComplete(int result) { 555 void HttpStreamFactoryImpl::Job::OnIOComplete(int result) {
552 TRACE_EVENT0(kNetTracingCategory, "HttpStreamFactoryImpl::Job::OnIOComplete"); 556 TRACE_EVENT0(kNetTracingCategory, "HttpStreamFactoryImpl::Job::OnIOComplete");
553 RunLoop(result); 557 RunLoop(result);
554 } 558 }
555 559
556 int HttpStreamFactoryImpl::Job::RunLoop(int result) { 560 int HttpStreamFactoryImpl::Job::RunLoop(int result) {
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 return rv; 950 return rv;
947 } 951 }
948 952
949 SpdySessionKey spdy_session_key = GetSpdySessionKey(); 953 SpdySessionKey spdy_session_key = GetSpdySessionKey();
950 954
951 // Check first if we have a spdy session for this group. If so, then go 955 // Check first if we have a spdy session for this group. If so, then go
952 // straight to using that. 956 // straight to using that.
953 if (CanUseExistingSpdySession()) { 957 if (CanUseExistingSpdySession()) {
954 base::WeakPtr<SpdySession> spdy_session = 958 base::WeakPtr<SpdySession> spdy_session =
955 session_->spdy_session_pool()->FindAvailableSession( 959 session_->spdy_session_pool()->FindAvailableSession(
956 spdy_session_key, origin_url_, /* enable_ip_based_pooling = */ true, 960 spdy_session_key, origin_url_, enable_ip_based_pooling_, net_log_);
957 net_log_);
958 if (spdy_session) { 961 if (spdy_session) {
959 // If we're preconnecting, but we already have a SpdySession, we don't 962 // If we're preconnecting, but we already have a SpdySession, we don't
960 // actually need to preconnect any sockets, so we're done. 963 // actually need to preconnect any sockets, so we're done.
961 if (job_type_ == PRECONNECT) 964 if (job_type_ == PRECONNECT)
962 return OK; 965 return OK;
963 using_spdy_ = true; 966 using_spdy_ = true;
964 next_state_ = STATE_CREATE_STREAM; 967 next_state_ = STATE_CREATE_STREAM;
965 existing_spdy_session_ = spdy_session; 968 existing_spdy_session_ = spdy_session;
966 return OK; 969 return OK;
967 } 970 }
(...skipping 26 matching lines...) Expand all
994 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, 997 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy,
995 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode, 998 server_ssl_config_, proxy_ssl_config_, request_info_.privacy_mode,
996 net_log_, num_streams_); 999 net_log_, num_streams_);
997 } 1000 }
998 1001
999 // If we can't use a SPDY session, don't bother checking for one after 1002 // If we can't use a SPDY session, don't bother checking for one after
1000 // the hostname is resolved. 1003 // the hostname is resolved.
1001 OnHostResolutionCallback resolution_callback = 1004 OnHostResolutionCallback resolution_callback =
1002 CanUseExistingSpdySession() 1005 CanUseExistingSpdySession()
1003 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(), 1006 ? base::Bind(&Job::OnHostResolution, session_->spdy_session_pool(),
1004 spdy_session_key, origin_url_) 1007 spdy_session_key, origin_url_, enable_ip_based_pooling_)
Zhongyi Shi 2017/03/29 03:05:06 ditto
Bence 2017/03/29 16:46:08 ditto
1005 : OnHostResolutionCallback(); 1008 : OnHostResolutionCallback();
1006 if (delegate_->for_websockets()) { 1009 if (delegate_->for_websockets()) {
1007 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported. 1010 // TODO(ricea): Re-enable NPN when WebSockets over SPDY is supported.
1008 SSLConfig websocket_server_ssl_config = server_ssl_config_; 1011 SSLConfig websocket_server_ssl_config = server_ssl_config_;
1009 websocket_server_ssl_config.alpn_protos.clear(); 1012 websocket_server_ssl_config.alpn_protos.clear();
1010 return InitSocketHandleForWebSocketRequest( 1013 return InitSocketHandleForWebSocketRequest(
1011 GetSocketGroup(), destination_, request_info_.extra_headers, 1014 GetSocketGroup(), destination_, request_info_.extra_headers,
1012 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy, 1015 request_info_.load_flags, priority_, session_, proxy_info_, expect_spdy,
1013 websocket_server_ssl_config, proxy_ssl_config_, 1016 websocket_server_ssl_config, proxy_ssl_config_,
1014 request_info_.privacy_mode, net_log_, connection_.get(), 1017 request_info_.privacy_mode, net_log_, connection_.get(),
(...skipping 14 matching lines...) Expand all
1029 DCHECK_EQ(OK, result); 1032 DCHECK_EQ(OK, result);
1030 return OK; 1033 return OK;
1031 } 1034 }
1032 1035
1033 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) { 1036 if (result == ERR_SPDY_SESSION_ALREADY_EXISTS) {
1034 // We found a SPDY connection after resolving the host. This is 1037 // We found a SPDY connection after resolving the host. This is
1035 // probably an IP pooled connection. 1038 // probably an IP pooled connection.
1036 SpdySessionKey spdy_session_key = GetSpdySessionKey(); 1039 SpdySessionKey spdy_session_key = GetSpdySessionKey();
1037 existing_spdy_session_ = 1040 existing_spdy_session_ =
1038 session_->spdy_session_pool()->FindAvailableSession( 1041 session_->spdy_session_pool()->FindAvailableSession(
1039 spdy_session_key, origin_url_, 1042 spdy_session_key, origin_url_, enable_ip_based_pooling_, net_log_);
1040 /* enable_ip_based_pooling = */ true, net_log_);
1041 if (existing_spdy_session_) { 1043 if (existing_spdy_session_) {
1042 using_spdy_ = true; 1044 using_spdy_ = true;
1043 next_state_ = STATE_CREATE_STREAM; 1045 next_state_ = STATE_CREATE_STREAM;
1044 } else { 1046 } else {
1045 // It is possible that the spdy session no longer exists. 1047 // It is possible that the spdy session no longer exists.
1046 ReturnToStateInitConnection(true /* close connection */); 1048 ReturnToStateInitConnection(true /* close connection */);
1047 } 1049 }
1048 return OK; 1050 return OK;
1049 } 1051 }
1050 1052
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 } 1244 }
1243 return OK; 1245 return OK;
1244 } 1246 }
1245 1247
1246 CHECK(!stream_.get()); 1248 CHECK(!stream_.get());
1247 1249
1248 SpdySessionKey spdy_session_key = GetSpdySessionKey(); 1250 SpdySessionKey spdy_session_key = GetSpdySessionKey();
1249 if (!existing_spdy_session_) { 1251 if (!existing_spdy_session_) {
1250 existing_spdy_session_ = 1252 existing_spdy_session_ =
1251 session_->spdy_session_pool()->FindAvailableSession( 1253 session_->spdy_session_pool()->FindAvailableSession(
1252 spdy_session_key, origin_url_, 1254 spdy_session_key, origin_url_, enable_ip_based_pooling_, net_log_);
1253 /* enable_ip_based_pooling = */ true, net_log_);
1254 } 1255 }
1255 bool direct = !IsHttpsProxyAndHttpUrl(); 1256 bool direct = !IsHttpsProxyAndHttpUrl();
1256 if (existing_spdy_session_.get()) { 1257 if (existing_spdy_session_.get()) {
1257 // We picked up an existing session, so we don't need our socket. 1258 // We picked up an existing session, so we don't need our socket.
1258 if (connection_->socket()) 1259 if (connection_->socket())
1259 connection_->socket()->Disconnect(); 1260 connection_->socket()->Disconnect();
1260 connection_->Reset(); 1261 connection_->Reset();
1261 1262
1262 int set_result = SetSpdyHttpStreamOrBidirectionalStreamImpl( 1263 int set_result = SetSpdyHttpStreamOrBidirectionalStreamImpl(
1263 existing_spdy_session_, direct); 1264 existing_spdy_session_, direct);
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 1556
1556 ConnectionAttempts socket_attempts = connection_->connection_attempts(); 1557 ConnectionAttempts socket_attempts = connection_->connection_attempts();
1557 if (connection_->socket()) { 1558 if (connection_->socket()) {
1558 connection_->socket()->GetConnectionAttempts(&socket_attempts); 1559 connection_->socket()->GetConnectionAttempts(&socket_attempts);
1559 } 1560 }
1560 1561
1561 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); 1562 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts);
1562 } 1563 }
1563 1564
1564 } // namespace net 1565 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698