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

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

Issue 4264: If we read nothing (EOF) after sending a request on a... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « net/http/http_network_transaction.h ('k') | net/http/http_network_transaction_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/trace_event.h" 9 #include "base/trace_event.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 char* buf = header_buf_.get() + header_buf_len_; 569 char* buf = header_buf_.get() + header_buf_len_;
570 int buf_len = header_buf_capacity_ - header_buf_len_; 570 int buf_len = header_buf_capacity_ - header_buf_len_;
571 571
572 return connection_.socket()->Read(buf, buf_len, &io_callback_); 572 return connection_.socket()->Read(buf, buf_len, &io_callback_);
573 } 573 }
574 574
575 int HttpNetworkTransaction::DoReadHeadersComplete(int result) { 575 int HttpNetworkTransaction::DoReadHeadersComplete(int result) {
576 if (result < 0) 576 if (result < 0)
577 return HandleIOError(result); 577 return HandleIOError(result);
578 578
579 if (result == 0 && ShouldResendRequest())
580 return result;
581
579 // Record our best estimate of the 'response time' as the time when we read 582 // Record our best estimate of the 'response time' as the time when we read
580 // the first bytes of the response headers. 583 // the first bytes of the response headers.
581 if (header_buf_len_ == 0) 584 if (header_buf_len_ == 0)
582 response_.response_time = Time::Now(); 585 response_.response_time = Time::Now();
583 586
584 // The socket was closed before we found end-of-headers. 587 // The socket was closed before we found end-of-headers.
585 if (result == 0) { 588 if (result == 0) {
586 if (establishing_tunnel_) { 589 if (establishing_tunnel_) {
587 // The socket was closed before the tunnel could be established. 590 // The socket was closed before the tunnel could be established.
588 return ERR_TUNNEL_CONNECTION_FAILED; 591 return ERR_TUNNEL_CONNECTION_FAILED;
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 // other cases, such as a Connect error. 844 // other cases, such as a Connect error.
842 int HttpNetworkTransaction::HandleIOError(int error) { 845 int HttpNetworkTransaction::HandleIOError(int error) {
843 switch (error) { 846 switch (error) {
844 // If we try to reuse a connection that the server is in the process of 847 // If we try to reuse a connection that the server is in the process of
845 // closing, we may end up successfully writing out our request (or a 848 // closing, we may end up successfully writing out our request (or a
846 // portion of our request) only to find a connection error when we try to 849 // portion of our request) only to find a connection error when we try to
847 // read from (or finish writing to) the socket. 850 // read from (or finish writing to) the socket.
848 case ERR_CONNECTION_RESET: 851 case ERR_CONNECTION_RESET:
849 case ERR_CONNECTION_CLOSED: 852 case ERR_CONNECTION_CLOSED:
850 case ERR_CONNECTION_ABORTED: 853 case ERR_CONNECTION_ABORTED:
851 if (!establishing_tunnel_ && 854 if (ShouldResendRequest())
852 reused_socket_ && // We reused a keep-alive connection.
853 !header_buf_len_) { // We haven't received any response header yet.
854 connection_.set_socket(NULL);
855 connection_.Reset();
856 request_headers_bytes_sent_ = 0;
857 if (request_body_stream_.get())
858 request_body_stream_->Reset();
859 next_state_ = STATE_INIT_CONNECTION; // Resend the request.
860 error = OK; 855 error = OK;
861 }
862 break; 856 break;
863 } 857 }
864 return error; 858 return error;
865 } 859 }
866 860
861 bool HttpNetworkTransaction::ShouldResendRequest() {
862 // NOTE: we resend a request only if we reused a keep-alive connection.
863 // This automatically prevents an infinite resend loop because we'll run
864 // out of the cached keep-alive connections eventually.
865 if (establishing_tunnel_ ||
866 !reused_socket_ || // We didn't reuse a keep-alive connection.
867 header_buf_len_) { // We have received some response headers.
868 return false;
869 }
870 connection_.set_socket(NULL);
871 connection_.Reset();
872 request_headers_bytes_sent_ = 0;
873 if (request_body_stream_.get())
874 request_body_stream_->Reset();
875 next_state_ = STATE_INIT_CONNECTION; // Resend the request.
876 return true;
877 }
878
867 } // namespace net 879 } // namespace net
868 880
OLDNEW
« no previous file with comments | « net/http/http_network_transaction.h ('k') | net/http/http_network_transaction_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698