OLD | NEW |
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 <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "net/http/http_chunked_decoder.h" | 38 #include "net/http/http_chunked_decoder.h" |
39 #include "net/http/http_network_session.h" | 39 #include "net/http/http_network_session.h" |
40 #include "net/http/http_proxy_client_socket.h" | 40 #include "net/http/http_proxy_client_socket.h" |
41 #include "net/http/http_proxy_client_socket_pool.h" | 41 #include "net/http/http_proxy_client_socket_pool.h" |
42 #include "net/http/http_request_headers.h" | 42 #include "net/http/http_request_headers.h" |
43 #include "net/http/http_request_info.h" | 43 #include "net/http/http_request_info.h" |
44 #include "net/http/http_response_headers.h" | 44 #include "net/http/http_response_headers.h" |
45 #include "net/http/http_response_info.h" | 45 #include "net/http/http_response_info.h" |
46 #include "net/http/http_server_properties.h" | 46 #include "net/http/http_server_properties.h" |
47 #include "net/http/http_status_code.h" | 47 #include "net/http/http_status_code.h" |
48 #include "net/http/http_stream_base.h" | 48 #include "net/http/http_stream.h" |
49 #include "net/http/http_stream_factory.h" | 49 #include "net/http/http_stream_factory.h" |
50 #include "net/http/http_util.h" | 50 #include "net/http/http_util.h" |
51 #include "net/http/transport_security_state.h" | 51 #include "net/http/transport_security_state.h" |
52 #include "net/http/url_security_manager.h" | 52 #include "net/http/url_security_manager.h" |
53 #include "net/socket/client_socket_factory.h" | 53 #include "net/socket/client_socket_factory.h" |
54 #include "net/socket/socks_client_socket_pool.h" | 54 #include "net/socket/socks_client_socket_pool.h" |
55 #include "net/socket/ssl_client_socket.h" | 55 #include "net/socket/ssl_client_socket.h" |
56 #include "net/socket/ssl_client_socket_pool.h" | 56 #include "net/socket/ssl_client_socket_pool.h" |
57 #include "net/socket/transport_client_socket_pool.h" | 57 #include "net/socket/transport_client_socket_pool.h" |
58 #include "net/spdy/hpack_huffman_aggregator.h" | 58 #include "net/spdy/hpack_huffman_aggregator.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 stream_->Close(true /* not reusable */); | 156 stream_->Close(true /* not reusable */); |
157 } else { | 157 } else { |
158 if (stream_->IsResponseBodyComplete()) { | 158 if (stream_->IsResponseBodyComplete()) { |
159 // If the response body is complete, we can just reuse the socket. | 159 // If the response body is complete, we can just reuse the socket. |
160 stream_->Close(false /* reusable */); | 160 stream_->Close(false /* reusable */); |
161 } else if (stream_->IsSpdyHttpStream()) { | 161 } else if (stream_->IsSpdyHttpStream()) { |
162 // Doesn't really matter for SpdyHttpStream. Just close it. | 162 // Doesn't really matter for SpdyHttpStream. Just close it. |
163 stream_->Close(true /* not reusable */); | 163 stream_->Close(true /* not reusable */); |
164 } else { | 164 } else { |
165 // Otherwise, we try to drain the response body. | 165 // Otherwise, we try to drain the response body. |
166 HttpStreamBase* stream = stream_.release(); | 166 HttpStream* stream = stream_.release(); |
167 stream->Drain(session_); | 167 stream->Drain(session_); |
168 } | 168 } |
169 } | 169 } |
170 } | 170 } |
171 | 171 |
172 if (request_ && request_->upload_data_stream) | 172 if (request_ && request_->upload_data_stream) |
173 request_->upload_data_stream->Reset(); // Invalidate pending callbacks. | 173 request_->upload_data_stream->Reset(); // Invalidate pending callbacks. |
174 } | 174 } |
175 | 175 |
176 int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info, | 176 int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) { | 298 void HttpNetworkTransaction::DidDrainBodyForAuthRestart(bool keep_alive) { |
299 DCHECK(!stream_request_.get()); | 299 DCHECK(!stream_request_.get()); |
300 | 300 |
301 if (stream_.get()) { | 301 if (stream_.get()) { |
302 total_received_bytes_ += stream_->GetTotalReceivedBytes(); | 302 total_received_bytes_ += stream_->GetTotalReceivedBytes(); |
303 HttpStream* new_stream = NULL; | 303 HttpStream* new_stream = NULL; |
304 if (keep_alive && stream_->IsConnectionReusable()) { | 304 if (keep_alive && stream_->IsConnectionReusable()) { |
305 // We should call connection_->set_idle_time(), but this doesn't occur | 305 // We should call connection_->set_idle_time(), but this doesn't occur |
306 // often enough to be worth the trouble. | 306 // often enough to be worth the trouble. |
307 stream_->SetConnectionReused(); | 307 stream_->SetConnectionReused(); |
308 new_stream = | 308 new_stream = stream_->RenewStreamForAuth(); |
309 static_cast<HttpStream*>(stream_.get())->RenewStreamForAuth(); | |
310 } | 309 } |
311 | 310 |
312 if (!new_stream) { | 311 if (!new_stream) { |
313 // Close the stream and mark it as not_reusable. Even in the | 312 // Close the stream and mark it as not_reusable. Even in the |
314 // keep_alive case, we've determined that the stream_ is not | 313 // keep_alive case, we've determined that the stream_ is not |
315 // reusable if new_stream is NULL. | 314 // reusable if new_stream is NULL. |
316 stream_->Close(true); | 315 stream_->Close(true); |
317 next_state_ = STATE_CREATE_STREAM; | 316 next_state_ = STATE_CREATE_STREAM; |
318 } else { | 317 } else { |
319 // Renewed streams shouldn't carry over received bytes. | 318 // Renewed streams shouldn't carry over received bytes. |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 return LOAD_STATE_READING_RESPONSE; | 413 return LOAD_STATE_READING_RESPONSE; |
415 default: | 414 default: |
416 return LOAD_STATE_IDLE; | 415 return LOAD_STATE_IDLE; |
417 } | 416 } |
418 } | 417 } |
419 | 418 |
420 UploadProgress HttpNetworkTransaction::GetUploadProgress() const { | 419 UploadProgress HttpNetworkTransaction::GetUploadProgress() const { |
421 if (!stream_.get()) | 420 if (!stream_.get()) |
422 return UploadProgress(); | 421 return UploadProgress(); |
423 | 422 |
424 // TODO(bashi): This cast is temporary. Remove later. | 423 return stream_->GetUploadProgress(); |
425 return static_cast<HttpStream*>(stream_.get())->GetUploadProgress(); | |
426 } | 424 } |
427 | 425 |
428 void HttpNetworkTransaction::SetQuicServerInfo( | 426 void HttpNetworkTransaction::SetQuicServerInfo( |
429 QuicServerInfo* quic_server_info) {} | 427 QuicServerInfo* quic_server_info) {} |
430 | 428 |
431 bool HttpNetworkTransaction::GetLoadTimingInfo( | 429 bool HttpNetworkTransaction::GetLoadTimingInfo( |
432 LoadTimingInfo* load_timing_info) const { | 430 LoadTimingInfo* load_timing_info) const { |
433 if (!stream_ || !stream_->GetLoadTimingInfo(load_timing_info)) | 431 if (!stream_ || !stream_->GetLoadTimingInfo(load_timing_info)) |
434 return false; | 432 return false; |
435 | 433 |
(...skipping 28 matching lines...) Expand all Loading... |
464 before_proxy_headers_sent_callback_ = callback; | 462 before_proxy_headers_sent_callback_ = callback; |
465 } | 463 } |
466 | 464 |
467 int HttpNetworkTransaction::ResumeNetworkStart() { | 465 int HttpNetworkTransaction::ResumeNetworkStart() { |
468 DCHECK_EQ(next_state_, STATE_CREATE_STREAM); | 466 DCHECK_EQ(next_state_, STATE_CREATE_STREAM); |
469 return DoLoop(OK); | 467 return DoLoop(OK); |
470 } | 468 } |
471 | 469 |
472 void HttpNetworkTransaction::OnStreamReady(const SSLConfig& used_ssl_config, | 470 void HttpNetworkTransaction::OnStreamReady(const SSLConfig& used_ssl_config, |
473 const ProxyInfo& used_proxy_info, | 471 const ProxyInfo& used_proxy_info, |
474 HttpStreamBase* stream) { | 472 HttpStream* stream) { |
475 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); | 473 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); |
476 DCHECK(stream_request_.get()); | 474 DCHECK(stream_request_.get()); |
477 | 475 |
478 if (stream_) | 476 if (stream_) |
479 total_received_bytes_ += stream_->GetTotalReceivedBytes(); | 477 total_received_bytes_ += stream_->GetTotalReceivedBytes(); |
480 stream_.reset(stream); | 478 stream_.reset(stream); |
481 server_ssl_config_ = used_ssl_config; | 479 server_ssl_config_ = used_ssl_config; |
482 proxy_info_ = used_proxy_info; | 480 proxy_info_ = used_proxy_info; |
483 response_.was_npn_negotiated = stream_request_->was_npn_negotiated(); | 481 response_.was_npn_negotiated = stream_request_->was_npn_negotiated(); |
484 response_.npn_negotiated_protocol = SSLClientSocket::NextProtoToString( | 482 response_.npn_negotiated_protocol = SSLClientSocket::NextProtoToString( |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 | 555 |
558 server_ssl_config_ = used_ssl_config; | 556 server_ssl_config_ = used_ssl_config; |
559 response_.cert_request_info = cert_info; | 557 response_.cert_request_info = cert_info; |
560 OnIOComplete(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); | 558 OnIOComplete(ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
561 } | 559 } |
562 | 560 |
563 void HttpNetworkTransaction::OnHttpsProxyTunnelResponse( | 561 void HttpNetworkTransaction::OnHttpsProxyTunnelResponse( |
564 const HttpResponseInfo& response_info, | 562 const HttpResponseInfo& response_info, |
565 const SSLConfig& used_ssl_config, | 563 const SSLConfig& used_ssl_config, |
566 const ProxyInfo& used_proxy_info, | 564 const ProxyInfo& used_proxy_info, |
567 HttpStreamBase* stream) { | 565 HttpStream* stream) { |
568 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); | 566 DCHECK_EQ(STATE_CREATE_STREAM_COMPLETE, next_state_); |
569 | 567 |
570 headers_valid_ = true; | 568 headers_valid_ = true; |
571 response_ = response_info; | 569 response_ = response_info; |
572 server_ssl_config_ = used_ssl_config; | 570 server_ssl_config_ = used_ssl_config; |
573 proxy_info_ = used_proxy_info; | 571 proxy_info_ = used_proxy_info; |
574 if (stream_) | 572 if (stream_) |
575 total_received_bytes_ += stream_->GetTotalReceivedBytes(); | 573 total_received_bytes_ += stream_->GetTotalReceivedBytes(); |
576 stream_.reset(stream); | 574 stream_.reset(stream); |
577 stream_request_.reset(); // we're done with the stream request | 575 stream_request_.reset(); // we're done with the stream request |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1524 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, | 1522 description = base::StringPrintf("Unknown state 0x%08X (%u)", state, |
1525 state); | 1523 state); |
1526 break; | 1524 break; |
1527 } | 1525 } |
1528 return description; | 1526 return description; |
1529 } | 1527 } |
1530 | 1528 |
1531 #undef STATE_CASE | 1529 #undef STATE_CASE |
1532 | 1530 |
1533 } // namespace net | 1531 } // namespace net |
OLD | NEW |