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/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" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/file_version_info.h" | 12 #include "base/file_version_info.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/macros.h" |
14 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
15 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
16 #include "base/profiler/scoped_tracker.h" | 17 #include "base/profiler/scoped_tracker.h" |
17 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
18 #include "base/single_thread_task_runner.h" | 19 #include "base/single_thread_task_runner.h" |
19 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
20 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
21 #include "base/time/time.h" | 22 #include "base/time/time.h" |
22 #include "base/values.h" | 23 #include "base/values.h" |
23 #include "net/base/host_port_pair.h" | 24 #include "net/base/host_port_pair.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 public: | 62 public: |
62 explicit HttpFilterContext(URLRequestHttpJob* job); | 63 explicit HttpFilterContext(URLRequestHttpJob* job); |
63 ~HttpFilterContext() override; | 64 ~HttpFilterContext() override; |
64 | 65 |
65 // FilterContext implementation. | 66 // FilterContext implementation. |
66 bool GetMimeType(std::string* mime_type) const override; | 67 bool GetMimeType(std::string* mime_type) const override; |
67 bool GetURL(GURL* gurl) const override; | 68 bool GetURL(GURL* gurl) const override; |
68 base::Time GetRequestTime() const override; | 69 base::Time GetRequestTime() const override; |
69 bool IsCachedContent() const override; | 70 bool IsCachedContent() const override; |
70 SdchManager::DictionarySet* SdchDictionariesAdvertised() const override; | 71 SdchManager::DictionarySet* SdchDictionariesAdvertised() const override; |
71 int64 GetByteReadCount() const override; | 72 int64_t GetByteReadCount() const override; |
72 int GetResponseCode() const override; | 73 int GetResponseCode() const override; |
73 const URLRequestContext* GetURLRequestContext() const override; | 74 const URLRequestContext* GetURLRequestContext() const override; |
74 void RecordPacketStats(StatisticSelector statistic) const override; | 75 void RecordPacketStats(StatisticSelector statistic) const override; |
75 const BoundNetLog& GetNetLog() const override; | 76 const BoundNetLog& GetNetLog() const override; |
76 | 77 |
77 private: | 78 private: |
78 URLRequestHttpJob* job_; | 79 URLRequestHttpJob* job_; |
79 | 80 |
80 // URLRequestHttpJob may be detached from URLRequest, but we still need to | 81 // URLRequestHttpJob may be detached from URLRequest, but we still need to |
81 // return something. | 82 // return something. |
(...skipping 28 matching lines...) Expand all Loading... |
110 | 111 |
111 bool URLRequestHttpJob::HttpFilterContext::IsCachedContent() const { | 112 bool URLRequestHttpJob::HttpFilterContext::IsCachedContent() const { |
112 return job_->is_cached_content_; | 113 return job_->is_cached_content_; |
113 } | 114 } |
114 | 115 |
115 SdchManager::DictionarySet* | 116 SdchManager::DictionarySet* |
116 URLRequestHttpJob::HttpFilterContext::SdchDictionariesAdvertised() const { | 117 URLRequestHttpJob::HttpFilterContext::SdchDictionariesAdvertised() const { |
117 return job_->dictionaries_advertised_.get(); | 118 return job_->dictionaries_advertised_.get(); |
118 } | 119 } |
119 | 120 |
120 int64 URLRequestHttpJob::HttpFilterContext::GetByteReadCount() const { | 121 int64_t URLRequestHttpJob::HttpFilterContext::GetByteReadCount() const { |
121 return job_->prefilter_bytes_read(); | 122 return job_->prefilter_bytes_read(); |
122 } | 123 } |
123 | 124 |
124 int URLRequestHttpJob::HttpFilterContext::GetResponseCode() const { | 125 int URLRequestHttpJob::HttpFilterContext::GetResponseCode() const { |
125 return job_->GetResponseCode(); | 126 return job_->GetResponseCode(); |
126 } | 127 } |
127 | 128 |
128 const URLRequestContext* | 129 const URLRequestContext* |
129 URLRequestHttpJob::HttpFilterContext::GetURLRequestContext() const { | 130 URLRequestHttpJob::HttpFilterContext::GetURLRequestContext() const { |
130 return job_->request() ? job_->request()->context() : NULL; | 131 return job_->request() ? job_->request()->context() : NULL; |
(...skipping 1185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 } | 1317 } |
1317 | 1318 |
1318 bool URLRequestHttpJob::ShouldFixMismatchedContentLength(int rv) const { | 1319 bool URLRequestHttpJob::ShouldFixMismatchedContentLength(int rv) const { |
1319 // Some servers send the body compressed, but specify the content length as | 1320 // Some servers send the body compressed, but specify the content length as |
1320 // the uncompressed size. Although this violates the HTTP spec we want to | 1321 // the uncompressed size. Although this violates the HTTP spec we want to |
1321 // support it (as IE and FireFox do), but *only* for an exact match. | 1322 // support it (as IE and FireFox do), but *only* for an exact match. |
1322 // See http://crbug.com/79694. | 1323 // See http://crbug.com/79694. |
1323 if (rv == ERR_CONTENT_LENGTH_MISMATCH || | 1324 if (rv == ERR_CONTENT_LENGTH_MISMATCH || |
1324 rv == ERR_INCOMPLETE_CHUNKED_ENCODING) { | 1325 rv == ERR_INCOMPLETE_CHUNKED_ENCODING) { |
1325 if (request_ && request_->response_headers()) { | 1326 if (request_ && request_->response_headers()) { |
1326 int64 expected_length = request_->response_headers()->GetContentLength(); | 1327 int64_t expected_length = |
| 1328 request_->response_headers()->GetContentLength(); |
1327 VLOG(1) << __FUNCTION__ << "() " | 1329 VLOG(1) << __FUNCTION__ << "() " |
1328 << "\"" << request_->url().spec() << "\"" | 1330 << "\"" << request_->url().spec() << "\"" |
1329 << " content-length = " << expected_length | 1331 << " content-length = " << expected_length |
1330 << " pre total = " << prefilter_bytes_read() | 1332 << " pre total = " << prefilter_bytes_read() |
1331 << " post total = " << postfilter_bytes_read(); | 1333 << " post total = " << postfilter_bytes_read(); |
1332 if (postfilter_bytes_read() == expected_length) { | 1334 if (postfilter_bytes_read() == expected_length) { |
1333 // Clear the error. | 1335 // Clear the error. |
1334 return true; | 1336 return true; |
1335 } | 1337 } |
1336 } | 1338 } |
(...skipping 27 matching lines...) Expand all Loading... |
1364 } | 1366 } |
1365 | 1367 |
1366 bool URLRequestHttpJob::GetFullRequestHeaders( | 1368 bool URLRequestHttpJob::GetFullRequestHeaders( |
1367 HttpRequestHeaders* headers) const { | 1369 HttpRequestHeaders* headers) const { |
1368 if (!transaction_) | 1370 if (!transaction_) |
1369 return false; | 1371 return false; |
1370 | 1372 |
1371 return transaction_->GetFullRequestHeaders(headers); | 1373 return transaction_->GetFullRequestHeaders(headers); |
1372 } | 1374 } |
1373 | 1375 |
1374 int64 URLRequestHttpJob::GetTotalReceivedBytes() const { | 1376 int64_t URLRequestHttpJob::GetTotalReceivedBytes() const { |
1375 int64_t total_received_bytes = | 1377 int64_t total_received_bytes = |
1376 total_received_bytes_from_previous_transactions_; | 1378 total_received_bytes_from_previous_transactions_; |
1377 if (transaction_) | 1379 if (transaction_) |
1378 total_received_bytes += transaction_->GetTotalReceivedBytes(); | 1380 total_received_bytes += transaction_->GetTotalReceivedBytes(); |
1379 return total_received_bytes; | 1381 return total_received_bytes; |
1380 } | 1382 } |
1381 | 1383 |
1382 int64_t URLRequestHttpJob::GetTotalSentBytes() const { | 1384 int64_t URLRequestHttpJob::GetTotalSentBytes() const { |
1383 int64_t total_sent_bytes = total_sent_bytes_from_previous_transactions_; | 1385 int64_t total_sent_bytes = total_sent_bytes_from_previous_transactions_; |
1384 if (transaction_) | 1386 if (transaction_) |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1573 return override_response_headers_.get() ? | 1575 return override_response_headers_.get() ? |
1574 override_response_headers_.get() : | 1576 override_response_headers_.get() : |
1575 transaction_->GetResponseInfo()->headers.get(); | 1577 transaction_->GetResponseInfo()->headers.get(); |
1576 } | 1578 } |
1577 | 1579 |
1578 void URLRequestHttpJob::NotifyURLRequestDestroyed() { | 1580 void URLRequestHttpJob::NotifyURLRequestDestroyed() { |
1579 awaiting_callback_ = false; | 1581 awaiting_callback_ = false; |
1580 } | 1582 } |
1581 | 1583 |
1582 } // namespace net | 1584 } // namespace net |
OLD | NEW |