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_stream_factory.h" | 44 #include "net/http/http_stream_factory.h" |
46 #include "net/http/http_util.h" | 45 #include "net/http/http_util.h" |
47 #include "net/http/url_security_manager.h" | 46 #include "net/http/url_security_manager.h" |
48 #include "net/socket/client_socket_factory.h" | 47 #include "net/socket/client_socket_factory.h" |
49 #include "net/socket/socks_client_socket_pool.h" | 48 #include "net/socket/socks_client_socket_pool.h" |
50 #include "net/socket/ssl_client_socket.h" | 49 #include "net/socket/ssl_client_socket.h" |
51 #include "net/socket/ssl_client_socket_pool.h" | 50 #include "net/socket/ssl_client_socket_pool.h" |
52 #include "net/socket/transport_client_socket_pool.h" | 51 #include "net/socket/transport_client_socket_pool.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 stream_->Close(true /* not reusable */); | 127 stream_->Close(true /* not reusable */); |
129 } else { | 128 } else { |
130 if (stream_->IsResponseBodyComplete()) { | 129 if (stream_->IsResponseBodyComplete()) { |
131 // If the response body is complete, we can just reuse the socket. | 130 // If the response body is complete, we can just reuse the socket. |
132 stream_->Close(false /* reusable */); | 131 stream_->Close(false /* reusable */); |
133 } else if (stream_->IsSpdyHttpStream()) { | 132 } else if (stream_->IsSpdyHttpStream()) { |
134 // Doesn't really matter for SpdyHttpStream. Just close it. | 133 // Doesn't really matter for SpdyHttpStream. Just close it. |
135 stream_->Close(true /* not reusable */); | 134 stream_->Close(true /* not reusable */); |
136 } else { | 135 } else { |
137 // Otherwise, we try to drain the response body. | 136 // Otherwise, we try to drain the response body. |
138 // TODO(willchan): Consider moving this response body draining to the | 137 HttpStream* stream = stream_.release(); |
139 // stream implementation. For SPDY, there's clearly no point. For | 138 stream->Drain(session_); |
140 // HTTP, it can vary depending on whether or not we're pipelining. It's | |
141 // stream dependent, so the different subtypes should be implementing | |
142 // their solutions. | |
143 HttpResponseBodyDrainer* drainer = | |
144 new HttpResponseBodyDrainer(stream_.release()); | |
145 drainer->Start(session_); | |
146 // |drainer| will delete itself. | |
147 } | 139 } |
148 } | 140 } |
149 } | 141 } |
150 } | 142 } |
151 | 143 |
152 int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info, | 144 int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info, |
153 CompletionCallback* callback, | 145 CompletionCallback* callback, |
154 const BoundNetLog& net_log) { | 146 const BoundNetLog& net_log) { |
155 SIMPLE_STATS_COUNTER("HttpNetworkTransaction.Count"); | 147 SIMPLE_STATS_COUNTER("HttpNetworkTransaction.Count"); |
156 | 148 |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 net_log_.EndEventWithNetErrorCode( | 532 net_log_.EndEventWithNetErrorCode( |
541 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, rv); | 533 NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, rv); |
542 break; | 534 break; |
543 case STATE_READ_HEADERS: | 535 case STATE_READ_HEADERS: |
544 DCHECK_EQ(OK, rv); | 536 DCHECK_EQ(OK, rv); |
545 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, NULL); | 537 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, NULL); |
546 rv = DoReadHeaders(); | 538 rv = DoReadHeaders(); |
547 break; | 539 break; |
548 case STATE_READ_HEADERS_COMPLETE: | 540 case STATE_READ_HEADERS_COMPLETE: |
549 rv = DoReadHeadersComplete(rv); | 541 rv = DoReadHeadersComplete(rv); |
550 net_log_.EndEventWithNetErrorCode( | |
551 NetLog::TYPE_HTTP_TRANSACTION_READ_HEADERS, rv); | |
willchan no longer on Chromium
2011/09/29 19:32:48
You should keep this back where it was.
James Simonsen
2011/10/12 01:36:58
Didn't mean to delete it. Forgot to save before up
| |
552 break; | 542 break; |
553 case STATE_READ_BODY: | 543 case STATE_READ_BODY: |
554 DCHECK_EQ(OK, rv); | 544 DCHECK_EQ(OK, rv); |
555 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, NULL); | 545 net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, NULL); |
556 rv = DoReadBody(); | 546 rv = DoReadBody(); |
557 break; | 547 break; |
558 case STATE_READ_BODY_COMPLETE: | 548 case STATE_READ_BODY_COMPLETE: |
559 rv = DoReadBodyComplete(rv); | 549 rv = DoReadBodyComplete(rv); |
560 net_log_.EndEventWithNetErrorCode( | 550 net_log_.EndEventWithNetErrorCode( |
561 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, rv); | 551 NetLog::TYPE_HTTP_TRANSACTION_READ_BODY, rv); |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
865 *response_.headers, | 855 *response_.headers, |
866 endpoint); | 856 endpoint); |
867 | 857 |
868 int rv = HandleAuthChallenge(); | 858 int rv = HandleAuthChallenge(); |
869 if (rv != OK) | 859 if (rv != OK) |
870 return rv; | 860 return rv; |
871 | 861 |
872 if (is_https_request()) | 862 if (is_https_request()) |
873 stream_->GetSSLInfo(&response_.ssl_info); | 863 stream_->GetSSLInfo(&response_.ssl_info); |
874 | 864 |
865 if (read_buf_len_) { | |
866 next_state_ = STATE_READ_BODY; | |
willchan no longer on Chromium
2011/09/29 19:32:48
I believe this is a bug. We should only transition
James Simonsen
2011/10/12 01:36:58
It's a tricky situation. Maybe I should just forge
willchan no longer on Chromium
2011/10/13 02:29:16
A new test? Because this shouldn't happen, since n
| |
867 } | |
868 | |
875 headers_valid_ = true; | 869 headers_valid_ = true; |
876 return OK; | 870 return OK; |
877 } | 871 } |
878 | 872 |
879 int HttpNetworkTransaction::DoReadBody() { | 873 int HttpNetworkTransaction::DoReadBody() { |
880 DCHECK(read_buf_); | 874 DCHECK(read_buf_); |
881 DCHECK_GT(read_buf_len_, 0); | 875 DCHECK_GT(read_buf_len_, 0); |
882 DCHECK(stream_ != NULL); | 876 DCHECK(stream_ != NULL); |
883 | 877 |
884 next_state_ = STATE_READ_BODY_COMPLETE; | 878 next_state_ = STATE_READ_BODY_COMPLETE; |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1179 // 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 |
1180 // with the underlying connection. Because the peer may request | 1174 // with the underlying connection. Because the peer may request |
1181 // renegotiation at any time, check and handle any possible SSL handshake | 1175 // renegotiation at any time, check and handle any possible SSL handshake |
1182 // related errors. In addition to renegotiation, TLS False/Snap Start may | 1176 // related errors. In addition to renegotiation, TLS False/Snap Start may |
1183 // 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 |
1184 // (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 |
1185 // connection. | 1179 // connection. |
1186 error = HandleSSLHandshakeError(error); | 1180 error = HandleSSLHandshakeError(error); |
1187 | 1181 |
1188 switch (error) { | 1182 switch (error) { |
1183 case ERR_PIPELINE_EVICTION: | |
willchan no longer on Chromium
2011/09/29 19:32:48
I think here you should log to net_log_. You shoul
James Simonsen
2011/10/12 01:36:58
Done.
| |
1184 error = RestartAfterPipelineEviction(); | |
1185 break; | |
1186 | |
1189 // If we try to reuse a connection that the server is in the process of | 1187 // If we try to reuse a connection that the server is in the process of |
1190 // closing, we may end up successfully writing out our request (or a | 1188 // closing, we may end up successfully writing out our request (or a |
1191 // portion of our request) only to find a connection error when we try to | 1189 // portion of our request) only to find a connection error when we try to |
1192 // read from (or finish writing to) the socket. | 1190 // read from (or finish writing to) the socket. |
1193 case ERR_CONNECTION_RESET: | 1191 case ERR_CONNECTION_RESET: |
1194 case ERR_CONNECTION_CLOSED: | 1192 case ERR_CONNECTION_CLOSED: |
1195 case ERR_CONNECTION_ABORTED: | 1193 case ERR_CONNECTION_ABORTED: |
1196 if (ShouldResendRequest(error)) { | 1194 if (ShouldResendRequest(error)) { |
1197 ResetConnectionAndRequestForResend(); | 1195 ResetConnectionAndRequestForResend(); |
1198 error = OK; | 1196 error = OK; |
1199 } | 1197 } |
1200 break; | 1198 break; |
1201 } | 1199 } |
1202 return error; | 1200 return error; |
1203 } | 1201 } |
1204 | 1202 |
1203 int HttpNetworkTransaction::RestartAfterPipelineEviction() { | |
1204 stream_->Close(true); | |
1205 stream_.reset(); | |
1206 stream_request_.reset(); | |
1207 next_state_ = STATE_CREATE_STREAM; | |
1208 return OK; | |
1209 } | |
1210 | |
1205 void HttpNetworkTransaction::ResetStateForRestart() { | 1211 void HttpNetworkTransaction::ResetStateForRestart() { |
1206 ResetStateForAuthRestart(); | 1212 ResetStateForAuthRestart(); |
1207 stream_.reset(); | 1213 stream_.reset(); |
1208 } | 1214 } |
1209 | 1215 |
1210 void HttpNetworkTransaction::ResetStateForAuthRestart() { | 1216 void HttpNetworkTransaction::ResetStateForAuthRestart() { |
1211 pending_auth_target_ = HttpAuth::AUTH_NONE; | 1217 pending_auth_target_ = HttpAuth::AUTH_NONE; |
1212 read_buf_ = NULL; | 1218 read_buf_ = NULL; |
1213 read_buf_len_ = 0; | 1219 read_buf_len_ = 0; |
1214 headers_valid_ = false; | 1220 headers_valid_ = false; |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1334 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, | 1340 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
1335 state); | 1341 state); |
1336 break; | 1342 break; |
1337 } | 1343 } |
1338 return description; | 1344 return description; |
1339 } | 1345 } |
1340 | 1346 |
1341 #undef STATE_CASE | 1347 #undef STATE_CASE |
1342 | 1348 |
1343 } // namespace net | 1349 } // namespace net |
OLD | NEW |