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

Side by Side Diff: net/url_request/url_request_http_job.cc

Issue 8863002: Revert 110505 - Report ERR_CONTENT_LENGTH_MISMATCH when the count of bytes received doesn't match... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years 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/url_request/url_request_http_job.h ('k') | net/url_request/url_request_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) 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/url_request/url_request_http_job.h" 5 #include "net/url_request/url_request_http_job.h"
6 6
7 #include "base/base_switches.h" 7 #include "base/base_switches.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/build_time.h" 10 #include "base/build_time.h"
(...skipping 747 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 void URLRequestHttpJob::OnHeadersReceivedCallback(int result) { 758 void URLRequestHttpJob::OnHeadersReceivedCallback(int result) {
759 request_->net_log().EndEvent( 759 request_->net_log().EndEvent(
760 NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); 760 NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL);
761 awaiting_callback_ = false; 761 awaiting_callback_ = false;
762 SaveCookiesAndNotifyHeadersComplete(result); 762 SaveCookiesAndNotifyHeadersComplete(result);
763 } 763 }
764 764
765 void URLRequestHttpJob::OnReadCompleted(int result) { 765 void URLRequestHttpJob::OnReadCompleted(int result) {
766 read_in_progress_ = false; 766 read_in_progress_ = false;
767 767
768 if (ShouldFixMismatchedContentLength(result))
769 result = 0;
770
768 if (result == 0) { 771 if (result == 0) {
769 NotifyDone(URLRequestStatus()); 772 NotifyDone(URLRequestStatus());
770 } else if (result < 0) { 773 } else if (result < 0) {
771 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); 774 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result));
772 } else { 775 } else {
773 // Clear the IO_PENDING status 776 // Clear the IO_PENDING status
774 SetStatus(URLRequestStatus()); 777 SetStatus(URLRequestStatus());
775 } 778 }
776 779
777 NotifyReadComplete(result); 780 NotifyReadComplete(result);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 return; 1096 return;
1094 1097
1095 // The transaction started synchronously, but we need to notify the 1098 // The transaction started synchronously, but we need to notify the
1096 // URLRequest delegate via the message loop. 1099 // URLRequest delegate via the message loop.
1097 MessageLoop::current()->PostTask( 1100 MessageLoop::current()->PostTask(
1098 FROM_HERE, 1101 FROM_HERE,
1099 method_factory_.NewRunnableMethod( 1102 method_factory_.NewRunnableMethod(
1100 &URLRequestHttpJob::OnStartCompleted, rv)); 1103 &URLRequestHttpJob::OnStartCompleted, rv));
1101 } 1104 }
1102 1105
1106 bool URLRequestHttpJob::ShouldFixMismatchedContentLength(int rv) const {
1107 // Some servers send the body compressed, but specify the content length as
1108 // the uncompressed size. Although this violates the HTTP spec we want to
1109 // support it (as IE and FireFox do), but *only* for an exact match.
1110 // See http://crbug.com/79694.
1111 if (rv == net::ERR_CONNECTION_CLOSED) {
1112 if (request_ && request_->response_headers()) {
1113 int64 expected_length = request_->response_headers()->GetContentLength();
1114 VLOG(1) << __FUNCTION__ << "() "
1115 << "\"" << request_->url().spec() << "\""
1116 << " content-length = " << expected_length
1117 << " pre total = " << prefilter_bytes_read()
1118 << " post total = " << postfilter_bytes_read();
1119 if (postfilter_bytes_read() == expected_length) {
1120 // Clear the error.
1121 return true;
1122 }
1123 }
1124 }
1125 return false;
1126 }
1127
1103 bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size, 1128 bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size,
1104 int* bytes_read) { 1129 int* bytes_read) {
1105 DCHECK_NE(buf_size, 0); 1130 DCHECK_NE(buf_size, 0);
1106 DCHECK(bytes_read); 1131 DCHECK(bytes_read);
1107 DCHECK(!read_in_progress_); 1132 DCHECK(!read_in_progress_);
1108 1133
1109 int rv = transaction_->Read(buf, buf_size, &read_callback_); 1134 int rv = transaction_->Read(buf, buf_size, &read_callback_);
1110 1135
1136 if (ShouldFixMismatchedContentLength(rv))
1137 rv = 0;
1138
1111 if (rv >= 0) { 1139 if (rv >= 0) {
1112 *bytes_read = rv; 1140 *bytes_read = rv;
1113 if (!rv) 1141 if (!rv)
1114 DoneWithRequest(FINISHED); 1142 DoneWithRequest(FINISHED);
1115 return true; 1143 return true;
1116 } 1144 }
1117 1145
1118 if (rv == ERR_IO_PENDING) { 1146 if (rv == ERR_IO_PENDING) {
1119 read_in_progress_ = true; 1147 read_in_progress_ = true;
1120 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); 1148 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 return override_response_headers_.get() ? 1440 return override_response_headers_.get() ?
1413 override_response_headers_ : 1441 override_response_headers_ :
1414 transaction_->GetResponseInfo()->headers; 1442 transaction_->GetResponseInfo()->headers;
1415 } 1443 }
1416 1444
1417 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1445 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1418 awaiting_callback_ = false; 1446 awaiting_callback_ = false;
1419 } 1447 }
1420 1448
1421 } // namespace net 1449 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698