OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "net/http/http_auth_handler.h" | 32 #include "net/http/http_auth_handler.h" |
33 #include "net/http/http_auth_handler_factory.h" | 33 #include "net/http/http_auth_handler_factory.h" |
34 #include "net/http/http_basic_stream.h" | 34 #include "net/http/http_basic_stream.h" |
35 #include "net/http/http_chunked_decoder.h" | 35 #include "net/http/http_chunked_decoder.h" |
36 #include "net/http/http_net_log_params.h" | 36 #include "net/http/http_net_log_params.h" |
37 #include "net/http/http_network_session.h" | 37 #include "net/http/http_network_session.h" |
38 #include "net/http/http_proxy_client_socket.h" | 38 #include "net/http/http_proxy_client_socket.h" |
39 #include "net/http/http_proxy_client_socket_pool.h" | 39 #include "net/http/http_proxy_client_socket_pool.h" |
40 #include "net/http/http_request_headers.h" | 40 #include "net/http/http_request_headers.h" |
41 #include "net/http/http_request_info.h" | 41 #include "net/http/http_request_info.h" |
42 #include "net/http/http_response_body_drainer.h" | |
43 #include "net/http/http_response_headers.h" | 42 #include "net/http/http_response_headers.h" |
44 #include "net/http/http_response_info.h" | 43 #include "net/http/http_response_info.h" |
45 #include "net/http/http_server_properties.h" | 44 #include "net/http/http_server_properties.h" |
46 #include "net/http/http_stream_factory.h" | 45 #include "net/http/http_stream_factory.h" |
47 #include "net/http/http_util.h" | 46 #include "net/http/http_util.h" |
48 #include "net/http/url_security_manager.h" | 47 #include "net/http/url_security_manager.h" |
49 #include "net/socket/client_socket_factory.h" | 48 #include "net/socket/client_socket_factory.h" |
50 #include "net/socket/socks_client_socket_pool.h" | 49 #include "net/socket/socks_client_socket_pool.h" |
51 #include "net/socket/ssl_client_socket.h" | 50 #include "net/socket/ssl_client_socket.h" |
52 #include "net/socket/ssl_client_socket_pool.h" | 51 #include "net/socket/ssl_client_socket_pool.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 stream_->Close(true /* not reusable */); | 129 stream_->Close(true /* not reusable */); |
131 } else { | 130 } else { |
132 if (stream_->IsResponseBodyComplete()) { | 131 if (stream_->IsResponseBodyComplete()) { |
133 // If the response body is complete, we can just reuse the socket. | 132 // If the response body is complete, we can just reuse the socket. |
134 stream_->Close(false /* reusable */); | 133 stream_->Close(false /* reusable */); |
135 } else if (stream_->IsSpdyHttpStream()) { | 134 } else if (stream_->IsSpdyHttpStream()) { |
136 // Doesn't really matter for SpdyHttpStream. Just close it. | 135 // Doesn't really matter for SpdyHttpStream. Just close it. |
137 stream_->Close(true /* not reusable */); | 136 stream_->Close(true /* not reusable */); |
138 } else { | 137 } else { |
139 // Otherwise, we try to drain the response body. | 138 // Otherwise, we try to drain the response body. |
140 // TODO(willchan): Consider moving this response body draining to the | 139 HttpStream* stream = stream_.release(); |
141 // stream implementation. For SPDY, there's clearly no point. For | 140 stream->Drain(session_); |
142 // HTTP, it can vary depending on whether or not we're pipelining. It's | |
143 // stream dependent, so the different subtypes should be implementing | |
144 // their solutions. | |
145 HttpResponseBodyDrainer* drainer = | |
146 new HttpResponseBodyDrainer(stream_.release()); | |
147 drainer->Start(session_); | |
148 // |drainer| will delete itself. | |
149 } | 141 } |
150 } | 142 } |
151 } | 143 } |
152 } | 144 } |
153 | 145 |
154 int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info, | 146 int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info, |
155 OldCompletionCallback* callback, | 147 OldCompletionCallback* callback, |
156 const BoundNetLog& net_log) { | 148 const BoundNetLog& net_log) { |
157 SIMPLE_STATS_COUNTER("HttpNetworkTransaction.Count"); | 149 SIMPLE_STATS_COUNTER("HttpNetworkTransaction.Count"); |
158 | 150 |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
544 net_log_.EndEventWithNetErrorCode( | 536 net_log_.EndEventWithNetErrorCode( |
545 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, rv); | 537 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, rv); |
546 break; | 538 break; |
547 case STATE_READ_HEADERS: | 539 case STATE_READ_HEADERS: |
548 DCHECK_EQ(OK, rv); | 540 DCHECK_EQ(OK, rv); |
549 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, NULL); | 541 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, NULL); |
550 rv = DoReadHeaders(); | 542 rv = DoReadHeaders(); |
551 break; | 543 break; |
552 case STATE_READ_HEADERS_COMPLETE: | 544 case STATE_READ_HEADERS_COMPLETE: |
553 rv = DoReadHeadersComplete(rv); | 545 rv = DoReadHeadersComplete(rv); |
554 net_log_.EndEventWithNetErrorCode( | |
555 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, rv); | |
556 break; | 546 break; |
557 case STATE_READ_BODY: | 547 case STATE_READ_BODY: |
558 DCHECK_EQ(OK, rv); | 548 DCHECK_EQ(OK, rv); |
559 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, NULL); | 549 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, NULL); |
560 rv = DoReadBody(); | 550 rv = DoReadBody(); |
561 break; | 551 break; |
562 case STATE_READ_BODY_COMPLETE: | 552 case STATE_READ_BODY_COMPLETE: |
563 rv = DoReadBodyComplete(rv); | 553 rv = DoReadBodyComplete(rv); |
564 net_log_.EndEventWithNetErrorCode( | 554 net_log_.EndEventWithNetErrorCode( |
565 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, rv); | 555 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, rv); |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1183 // SSL errors may happen at any time during the stream and indicate issues | 1173 // SSL errors may happen at any time during the stream and indicate issues |
1184 // with the underlying connection. Because the peer may request | 1174 // with the underlying connection. Because the peer may request |
1185 // renegotiation at any time, check and handle any possible SSL handshake | 1175 // renegotiation at any time, check and handle any possible SSL handshake |
1186 // related errors. In addition to renegotiation, TLS False/Snap Start may | 1176 // related errors. In addition to renegotiation, TLS False/Snap Start may |
1187 // cause SSL handshake errors to be delayed until the first or second Write | 1177 // cause SSL handshake errors to be delayed until the first or second Write |
1188 // (Snap Start) or the first Read (False & Snap Start) on the underlying | 1178 // (Snap Start) or the first Read (False & Snap Start) on the underlying |
1189 // connection. | 1179 // connection. |
1190 error = HandleSSLHandshakeError(error); | 1180 error = HandleSSLHandshakeError(error); |
1191 | 1181 |
1192 switch (error) { | 1182 switch (error) { |
1183 case ERR_PIPELINE_EVICTION: | |
1184 net_log_.AddEvent( | |
1185 NetLog::TYPE_HTTP_TRANSACTION_RESTART_AFTER_ERROR, | |
1186 make_scoped_refptr(new NetLogIntegerParameter("net_error", error))); | |
mmenke
2011/10/12 19:41:35
nit: I have a CL under review which lets you just
James Simonsen
2011/10/12 21:55:51
Nice. Will switch when it's ready.
mmenke
2011/10/13 03:02:48
No need to hold off committing on this. Haven't h
| |
1187 error = RestartAfterPipelineEviction(); | |
1188 break; | |
1189 | |
1193 // If we try to reuse a connection that the server is in the process of | 1190 // If we try to reuse a connection that the server is in the process of |
1194 // closing, we may end up successfully writing out our request (or a | 1191 // closing, we may end up successfully writing out our request (or a |
1195 // portion of our request) only to find a connection error when we try to | 1192 // portion of our request) only to find a connection error when we try to |
1196 // read from (or finish writing to) the socket. | 1193 // read from (or finish writing to) the socket. |
1197 case ERR_CONNECTION_RESET: | 1194 case ERR_CONNECTION_RESET: |
1198 case ERR_CONNECTION_CLOSED: | 1195 case ERR_CONNECTION_CLOSED: |
1199 case ERR_CONNECTION_ABORTED: | 1196 case ERR_CONNECTION_ABORTED: |
1200 if (ShouldResendRequest(error)) { | 1197 if (ShouldResendRequest(error)) { |
1198 net_log_.AddEvent( | |
1199 NetLog::TYPE_HTTP_TRANSACTION_RESTART_AFTER_ERROR, | |
1200 make_scoped_refptr(new NetLogIntegerParameter("net_error", error))); | |
1201 ResetConnectionAndRequestForResend(); | 1201 ResetConnectionAndRequestForResend(); |
1202 error = OK; | 1202 error = OK; |
1203 } | 1203 } |
1204 break; | 1204 break; |
1205 } | 1205 } |
1206 return error; | 1206 return error; |
1207 } | 1207 } |
1208 | 1208 |
1209 int HttpNetworkTransaction::RestartAfterPipelineEviction() { | |
1210 stream_->Close(true); | |
1211 stream_.reset(); | |
1212 stream_request_.reset(); | |
1213 next_state_ = STATE_CREATE_STREAM; | |
1214 return OK; | |
1215 } | |
1216 | |
1209 void HttpNetworkTransaction::ResetStateForRestart() { | 1217 void HttpNetworkTransaction::ResetStateForRestart() { |
1210 ResetStateForAuthRestart(); | 1218 ResetStateForAuthRestart(); |
1211 stream_.reset(); | 1219 stream_.reset(); |
1212 } | 1220 } |
1213 | 1221 |
1214 void HttpNetworkTransaction::ResetStateForAuthRestart() { | 1222 void HttpNetworkTransaction::ResetStateForAuthRestart() { |
1215 pending_auth_target_ = HttpAuth::AUTH_NONE; | 1223 pending_auth_target_ = HttpAuth::AUTH_NONE; |
1216 read_buf_ = NULL; | 1224 read_buf_ = NULL; |
1217 read_buf_len_ = 0; | 1225 read_buf_len_ = 0; |
1218 headers_valid_ = false; | 1226 headers_valid_ = false; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1338 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, | 1346 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
1339 state); | 1347 state); |
1340 break; | 1348 break; |
1341 } | 1349 } |
1342 return description; | 1350 return description; |
1343 } | 1351 } |
1344 | 1352 |
1345 #undef STATE_CASE | 1353 #undef STATE_CASE |
1346 | 1354 |
1347 } // namespace net | 1355 } // namespace net |
OLD | NEW |