Chromium Code Reviews| 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 569 case STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE: | 561 case STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE: |
| 570 rv = DoDrainBodyForAuthRestartComplete(rv); | 562 rv = DoDrainBodyForAuthRestartComplete(rv); |
| 571 net_log_.EndEventWithNetErrorCode( | 563 net_log_.EndEventWithNetErrorCode( |
| 572 NetLog::TYPE_HTTP_TRANSACTION_DRAIN_BODY_FOR_AUTH_RESTART, rv); | 564 NetLog::TYPE_HTTP_TRANSACTION_DRAIN_BODY_FOR_AUTH_RESTART, rv); |
| 573 break; | 565 break; |
| 574 default: | 566 default: |
| 575 NOTREACHED() << "bad state"; | 567 NOTREACHED() << "bad state"; |
| 576 rv = ERR_FAILED; | 568 rv = ERR_FAILED; |
| 577 break; | 569 break; |
| 578 } | 570 } |
| 571 if (rv == ERR_PIPELINE_EVICTION) { | |
|
willchan no longer on Chromium
2011/09/26 23:49:20
This is breaking our paradigm for the state machin
James Simonsen
2011/09/29 02:39:31
It's for the sake of logging. I want to return ERR
willchan no longer on Chromium
2011/09/29 19:32:48
I pointed out where I think you should do the logg
| |
| 572 rv = RestartAfterPipelineEviction(); | |
| 573 } | |
| 579 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 574 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 580 | 575 |
| 581 return rv; | 576 return rv; |
| 582 } | 577 } |
| 583 | 578 |
| 584 int HttpNetworkTransaction::DoCreateStream() { | 579 int HttpNetworkTransaction::DoCreateStream() { |
| 585 next_state_ = STATE_CREATE_STREAM_COMPLETE; | 580 next_state_ = STATE_CREATE_STREAM_COMPLETE; |
| 586 | 581 |
| 587 stream_request_.reset( | 582 stream_request_.reset( |
| 588 session_->http_stream_factory()->RequestStream( | 583 session_->http_stream_factory()->RequestStream( |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 865 *response_.headers, | 860 *response_.headers, |
| 866 endpoint); | 861 endpoint); |
| 867 | 862 |
| 868 int rv = HandleAuthChallenge(); | 863 int rv = HandleAuthChallenge(); |
| 869 if (rv != OK) | 864 if (rv != OK) |
| 870 return rv; | 865 return rv; |
| 871 | 866 |
| 872 if (is_https_request()) | 867 if (is_https_request()) |
| 873 stream_->GetSSLInfo(&response_.ssl_info); | 868 stream_->GetSSLInfo(&response_.ssl_info); |
| 874 | 869 |
| 870 if (read_buf_len_) { | |
| 871 next_state_ = STATE_READ_BODY; | |
| 872 } | |
| 873 | |
| 875 headers_valid_ = true; | 874 headers_valid_ = true; |
| 876 return OK; | 875 return OK; |
| 877 } | 876 } |
| 878 | 877 |
| 879 int HttpNetworkTransaction::DoReadBody() { | 878 int HttpNetworkTransaction::DoReadBody() { |
| 880 DCHECK(read_buf_); | 879 DCHECK(read_buf_); |
| 881 DCHECK_GT(read_buf_len_, 0); | 880 DCHECK_GT(read_buf_len_, 0); |
| 882 DCHECK(stream_ != NULL); | 881 DCHECK(stream_ != NULL); |
| 883 | 882 |
| 884 next_state_ = STATE_READ_BODY_COMPLETE; | 883 next_state_ = STATE_READ_BODY_COMPLETE; |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1195 case ERR_CONNECTION_ABORTED: | 1194 case ERR_CONNECTION_ABORTED: |
| 1196 if (ShouldResendRequest(error)) { | 1195 if (ShouldResendRequest(error)) { |
| 1197 ResetConnectionAndRequestForResend(); | 1196 ResetConnectionAndRequestForResend(); |
| 1198 error = OK; | 1197 error = OK; |
| 1199 } | 1198 } |
| 1200 break; | 1199 break; |
| 1201 } | 1200 } |
| 1202 return error; | 1201 return error; |
| 1203 } | 1202 } |
| 1204 | 1203 |
| 1204 int HttpNetworkTransaction::RestartAfterPipelineEviction() { | |
| 1205 stream_->Close(true); | |
| 1206 stream_.reset(); | |
| 1207 stream_request_.reset(); | |
| 1208 next_state_ = STATE_NONE; | |
| 1209 return RestartIgnoringLastError(user_callback_); | |
| 1210 } | |
| 1211 | |
| 1205 void HttpNetworkTransaction::ResetStateForRestart() { | 1212 void HttpNetworkTransaction::ResetStateForRestart() { |
| 1206 ResetStateForAuthRestart(); | 1213 ResetStateForAuthRestart(); |
| 1207 stream_.reset(); | 1214 stream_.reset(); |
| 1208 } | 1215 } |
| 1209 | 1216 |
| 1210 void HttpNetworkTransaction::ResetStateForAuthRestart() { | 1217 void HttpNetworkTransaction::ResetStateForAuthRestart() { |
| 1211 pending_auth_target_ = HttpAuth::AUTH_NONE; | 1218 pending_auth_target_ = HttpAuth::AUTH_NONE; |
| 1212 read_buf_ = NULL; | 1219 read_buf_ = NULL; |
| 1213 read_buf_len_ = 0; | 1220 read_buf_len_ = 0; |
| 1214 headers_valid_ = false; | 1221 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, | 1341 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
| 1335 state); | 1342 state); |
| 1336 break; | 1343 break; |
| 1337 } | 1344 } |
| 1338 return description; | 1345 return description; |
| 1339 } | 1346 } |
| 1340 | 1347 |
| 1341 #undef STATE_CASE | 1348 #undef STATE_CASE |
| 1342 | 1349 |
| 1343 } // namespace net | 1350 } // namespace net |
| OLD | NEW |