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/url_request/url_request_http_job.h" | 5 #include "net/url_request/url_request_http_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/base_switches.h" | 8 #include "base/base_switches.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 void URLRequestHttpJob::OnHeadersReceivedCallback(int result) { | 744 void URLRequestHttpJob::OnHeadersReceivedCallback(int result) { |
745 request_->net_log().EndEvent( | 745 request_->net_log().EndEvent( |
746 NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 746 NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
747 awaiting_callback_ = false; | 747 awaiting_callback_ = false; |
748 SaveCookiesAndNotifyHeadersComplete(result); | 748 SaveCookiesAndNotifyHeadersComplete(result); |
749 } | 749 } |
750 | 750 |
751 void URLRequestHttpJob::OnReadCompleted(int result) { | 751 void URLRequestHttpJob::OnReadCompleted(int result) { |
752 read_in_progress_ = false; | 752 read_in_progress_ = false; |
753 | 753 |
754 if (ShouldFixMismatchedContentLength(result)) | |
755 result = 0; | |
756 | |
757 if (result == 0) { | 754 if (result == 0) { |
758 NotifyDone(URLRequestStatus()); | 755 NotifyDone(URLRequestStatus()); |
759 } else if (result < 0) { | 756 } else if (result < 0) { |
760 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); | 757 NotifyDone(URLRequestStatus(URLRequestStatus::FAILED, result)); |
761 } else { | 758 } else { |
762 // Clear the IO_PENDING status | 759 // Clear the IO_PENDING status |
763 SetStatus(URLRequestStatus()); | 760 SetStatus(URLRequestStatus()); |
764 } | 761 } |
765 | 762 |
766 NotifyReadComplete(result); | 763 NotifyReadComplete(result); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 return; | 1079 return; |
1083 | 1080 |
1084 // The transaction started synchronously, but we need to notify the | 1081 // The transaction started synchronously, but we need to notify the |
1085 // URLRequest delegate via the message loop. | 1082 // URLRequest delegate via the message loop. |
1086 MessageLoop::current()->PostTask( | 1083 MessageLoop::current()->PostTask( |
1087 FROM_HERE, | 1084 FROM_HERE, |
1088 method_factory_.NewRunnableMethod( | 1085 method_factory_.NewRunnableMethod( |
1089 &URLRequestHttpJob::OnStartCompleted, rv)); | 1086 &URLRequestHttpJob::OnStartCompleted, rv)); |
1090 } | 1087 } |
1091 | 1088 |
1092 bool URLRequestHttpJob::ShouldFixMismatchedContentLength(int rv) const { | |
1093 // Some servers send the body compressed, but specify the content length as | |
1094 // the uncompressed size. Although this violates the HTTP spec we want to | |
1095 // support it (as IE and FireFox do), but *only* for an exact match. | |
1096 // See http://crbug.com/79694. | |
1097 if (rv == net::ERR_CONNECTION_CLOSED) { | |
1098 if (request_ && request_->response_headers()) { | |
1099 int64 expected_length = request_->response_headers()->GetContentLength(); | |
1100 VLOG(1) << __FUNCTION__ << "() " | |
1101 << "\"" << request_->url().spec() << "\"" | |
1102 << " content-length = " << expected_length | |
1103 << " pre total = " << prefilter_bytes_read() | |
1104 << " post total = " << postfilter_bytes_read(); | |
1105 if (postfilter_bytes_read() == expected_length) { | |
1106 // Clear the error. | |
1107 return true; | |
1108 } | |
1109 } | |
1110 } | |
1111 return false; | |
1112 } | |
1113 | |
1114 bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size, | 1089 bool URLRequestHttpJob::ReadRawData(IOBuffer* buf, int buf_size, |
1115 int* bytes_read) { | 1090 int* bytes_read) { |
1116 DCHECK_NE(buf_size, 0); | 1091 DCHECK_NE(buf_size, 0); |
1117 DCHECK(bytes_read); | 1092 DCHECK(bytes_read); |
1118 DCHECK(!read_in_progress_); | 1093 DCHECK(!read_in_progress_); |
1119 | 1094 |
1120 int rv = transaction_->Read(buf, buf_size, &read_callback_); | 1095 int rv = transaction_->Read(buf, buf_size, &read_callback_); |
1121 | 1096 |
1122 if (ShouldFixMismatchedContentLength(rv)) | |
1123 rv = 0; | |
1124 | |
1125 if (rv >= 0) { | 1097 if (rv >= 0) { |
1126 *bytes_read = rv; | 1098 *bytes_read = rv; |
1127 if (!rv) | 1099 if (!rv) |
1128 DoneWithRequest(FINISHED); | 1100 DoneWithRequest(FINISHED); |
1129 return true; | 1101 return true; |
1130 } | 1102 } |
1131 | 1103 |
1132 if (rv == ERR_IO_PENDING) { | 1104 if (rv == ERR_IO_PENDING) { |
1133 read_in_progress_ = true; | 1105 read_in_progress_ = true; |
1134 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); | 1106 SetStatus(URLRequestStatus(URLRequestStatus::IO_PENDING, 0)); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1426 return override_response_headers_.get() ? | 1398 return override_response_headers_.get() ? |
1427 override_response_headers_ : | 1399 override_response_headers_ : |
1428 transaction_->GetResponseInfo()->headers; | 1400 transaction_->GetResponseInfo()->headers; |
1429 } | 1401 } |
1430 | 1402 |
1431 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1403 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1432 awaiting_callback_ = false; | 1404 awaiting_callback_ = false; |
1433 } | 1405 } |
1434 | 1406 |
1435 } // namespace net | 1407 } // namespace net |
OLD | NEW |