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

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

Issue 9811006: Ignore Content-Length mismatches when Content-Length is too large. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove browser_tests Created 8 years, 9 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
OLDNEW
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/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/command_line.h" 10 #include "base/command_line.h"
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
747 747
748 // Check that there are no callbacks to already canceled requests. 748 // Check that there are no callbacks to already canceled requests.
749 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status()); 749 DCHECK_NE(URLRequestStatus::CANCELED, GetStatus().status());
750 750
751 SaveCookiesAndNotifyHeadersComplete(result); 751 SaveCookiesAndNotifyHeadersComplete(result);
752 } 752 }
753 753
754 void URLRequestHttpJob::OnReadCompleted(int result) { 754 void URLRequestHttpJob::OnReadCompleted(int result) {
755 read_in_progress_ = false; 755 read_in_progress_ = false;
756 756
757 if (ShouldFixMismatchedContentLength(result))
758 result = 0;
759
760 if (result == 0) { 757 if (result == 0) {
761 NotifyDone(URLRequestStatus()); 758 NotifyDone(URLRequestStatus());
762 } else if (result < 0) { 759 } else if (result < 0) {
763 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); 760 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result));
764 } else { 761 } else {
765 // Clear the IO_PENDING status 762 // Clear the IO_PENDING status
766 SetStatus(URLRequestStatus()); 763 SetStatus(URLRequestStatus());
767 } 764 }
768 765
769 NotifyReadComplete(result); 766 NotifyReadComplete(result);
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 return; 1083 return;
1087 1084
1088 // The transaction started synchronously, but we need to notify the 1085 // The transaction started synchronously, but we need to notify the
1089 // URLRequest delegate via the message loop. 1086 // URLRequest delegate via the message loop.
1090 MessageLoop::current()->PostTask( 1087 MessageLoop::current()->PostTask(
1091 FROM_HERE, 1088 FROM_HERE,
1092 base::Bind(&URLRequestHttpJob::OnStartCompleted, 1089 base::Bind(&URLRequestHttpJob::OnStartCompleted,
1093 weak_factory_.GetWeakPtr(), rv)); 1090 weak_factory_.GetWeakPtr(), rv));
1094 } 1091 }
1095 1092
1096 bool URLRequestHttpJob::ShouldFixMismatchedContentLength(int rv) const {
1097 // Some servers send the body compressed, but specify the content length as
1098 // the uncompressed size. Although this violates the HTTP spec we want to
1099 // support it (as IE and FireFox do), but *only* for an exact match.
1100 // See http://crbug.com/79694.
1101 if (rv == net::ERR_CONNECTION_CLOSED) {
1102 if (request_ && request_->response_headers()) {
1103 int64 expected_length = request_->response_headers()->GetContentLength();
1104 VLOG(1) << __FUNCTION__ << "() "
1105 << "\"" << request_->url().spec() << "\""
1106 << " content-length = " << expected_length
1107 << " pre total = " << prefilter_bytes_read()
1108 << " post total = " << postfilter_bytes_read();
1109 if (postfilter_bytes_read() == expected_length) {
1110 // Clear the error.
1111 return true;
1112 }
1113 }
1114 }
1115 return false;
1116 }
1117
1118 bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size, 1093 bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size,
1119 int* bytes_read) { 1094 int* bytes_read) {
1120 DCHECK_NE(buf_size, 0); 1095 DCHECK_NE(buf_size, 0);
1121 DCHECK(bytes_read); 1096 DCHECK(bytes_read);
1122 DCHECK(!read_in_progress_); 1097 DCHECK(!read_in_progress_);
1123 1098
1124 int rv = transaction_->Read( 1099 int rv = transaction_->Read(
1125 buf, buf_size, 1100 buf, buf_size,
1126 base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this))); 1101 base::Bind(&URLRequestHttpJob::OnReadCompleted, base::Unretained(this)));
1127 1102
1128 if (ShouldFixMismatchedContentLength(rv))
1129 rv = 0;
1130
1131 if (rv >= 0) { 1103 if (rv >= 0) {
1132 *bytes_read = rv; 1104 *bytes_read = rv;
1133 if (!rv) 1105 if (!rv)
1134 DoneWithRequest(FINISHED); 1106 DoneWithRequest(FINISHED);
1135 return true; 1107 return true;
1136 } 1108 }
1137 1109
1138 if (rv == ERR_IO_PENDING) { 1110 if (rv == ERR_IO_PENDING) {
1139 read_in_progress_ = true; 1111 read_in_progress_ = true;
1140 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); 1112 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0));
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 return override_response_headers_.get() ? 1387 return override_response_headers_.get() ?
1416 override_response_headers_ : 1388 override_response_headers_ :
1417 transaction_->GetResponseInfo()->headers; 1389 transaction_->GetResponseInfo()->headers;
1418 } 1390 }
1419 1391
1420 void URLRequestHttpJob::NotifyURLRequestDestroyed() { 1392 void URLRequestHttpJob::NotifyURLRequestDestroyed() {
1421 awaiting_callback_ = false; 1393 awaiting_callback_ = false;
1422 } 1394 }
1423 1395
1424 } // namespace net 1396 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698