| 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_job.h" | 5 #include "net/url_request/url_request_job.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/power_monitor/power_monitor.h" | 10 #include "base/power_monitor/power_monitor.h" |
| 11 #include "base/profiler/scoped_tracker.h" | 11 #include "base/profiler/scoped_tracker.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "net/base/auth.h" | 15 #include "net/base/auth.h" |
| 16 #include "net/base/host_port_pair.h" | 16 #include "net/base/host_port_pair.h" |
| 17 #include "net/base/io_buffer.h" | 17 #include "net/base/io_buffer.h" |
| 18 #include "net/base/load_states.h" | 18 #include "net/base/load_states.h" |
| 19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 20 #include "net/base/network_delegate.h" | 20 #include "net/base/network_delegate.h" |
| 21 #include "net/filter/filter.h" | 21 #include "net/filter/filter.h" |
| 22 #include "net/http/http_response_headers.h" | 22 #include "net/http/http_response_headers.h" |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Callback for TYPE_URL_REQUEST_FILTERS_SET net-internals event. | 28 // Callback for TYPE_URL_REQUEST_FILTERS_SET net-internals event. |
| 29 base::Value* FiltersSetCallback(Filter* filter, | 29 scoped_ptr<base::Value> FiltersSetCallback( |
| 30 NetLogCaptureMode /* capture_mode */) { | 30 Filter* filter, |
| 31 NetLogCaptureMode /* capture_mode */) { |
| 31 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); | 32 scoped_ptr<base::DictionaryValue> event_params(new base::DictionaryValue()); |
| 32 event_params->SetString("filters", filter->OrderedFilterList()); | 33 event_params->SetString("filters", filter->OrderedFilterList()); |
| 33 return event_params.release(); | 34 return event_params.Pass(); |
| 34 } | 35 } |
| 35 | 36 |
| 36 std::string ComputeMethodForRedirect(const std::string& method, | 37 std::string ComputeMethodForRedirect(const std::string& method, |
| 37 int http_status_code) { | 38 int http_status_code) { |
| 38 // For 303 redirects, all request methods except HEAD are converted to GET, | 39 // For 303 redirects, all request methods except HEAD are converted to GET, |
| 39 // as per the latest httpbis draft. The draft also allows POST requests to | 40 // as per the latest httpbis draft. The draft also allows POST requests to |
| 40 // be converted to GETs when following 301/302 redirects, for historical | 41 // be converted to GETs when following 301/302 redirects, for historical |
| 41 // reasons. Most major browsers do this and so shall we. Both RFC 2616 and | 42 // reasons. Most major browsers do this and so shall we. Both RFC 2616 and |
| 42 // the httpbis draft say to prompt the user to confirm the generation of new | 43 // the httpbis draft say to prompt the user to confirm the generation of new |
| 43 // requests, other than GET and HEAD requests, but IE omits these prompts and | 44 // requests, other than GET and HEAD requests, but IE omits these prompts and |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 filter_.reset(SetupFilter()); | 434 filter_.reset(SetupFilter()); |
| 434 | 435 |
| 435 if (!filter_.get()) { | 436 if (!filter_.get()) { |
| 436 std::string content_length; | 437 std::string content_length; |
| 437 request_->GetResponseHeaderByName("content-length", &content_length); | 438 request_->GetResponseHeaderByName("content-length", &content_length); |
| 438 if (!content_length.empty()) | 439 if (!content_length.empty()) |
| 439 base::StringToInt64(content_length, &expected_content_size_); | 440 base::StringToInt64(content_length, &expected_content_size_); |
| 440 } else { | 441 } else { |
| 441 request_->net_log().AddEvent( | 442 request_->net_log().AddEvent( |
| 442 NetLog::TYPE_URL_REQUEST_FILTERS_SET, | 443 NetLog::TYPE_URL_REQUEST_FILTERS_SET, |
| 443 base::Bind(&FiltersSetCallback, base::Unretained(filter_.get()))); | 444 base::Bind(FiltersSetCallback, base::Unretained(filter_.get()))); |
| 444 } | 445 } |
| 445 | 446 |
| 446 request_->NotifyResponseStarted(); | 447 request_->NotifyResponseStarted(); |
| 447 } | 448 } |
| 448 | 449 |
| 449 void URLRequestJob::NotifyReadComplete(int bytes_read) { | 450 void URLRequestJob::NotifyReadComplete(int bytes_read) { |
| 450 // TODO(cbentzel): Remove ScopedTracker below once crbug.com/475755 is fixed. | 451 // TODO(cbentzel): Remove ScopedTracker below once crbug.com/475755 is fixed. |
| 451 tracked_objects::ScopedTracker tracking_profile( | 452 tracked_objects::ScopedTracker tracking_profile( |
| 452 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 453 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 453 "475755 URLRequestJob::NotifyReadComplete")); | 454 "475755 URLRequestJob::NotifyReadComplete")); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 865 // Alter the referrer if redirecting cross-origin (especially HTTP->HTTPS). | 866 // Alter the referrer if redirecting cross-origin (especially HTTP->HTTPS). |
| 866 redirect_info.new_referrer = | 867 redirect_info.new_referrer = |
| 867 ComputeReferrerForRedirect(request_->referrer_policy(), | 868 ComputeReferrerForRedirect(request_->referrer_policy(), |
| 868 request_->referrer(), | 869 request_->referrer(), |
| 869 redirect_info.new_url).spec(); | 870 redirect_info.new_url).spec(); |
| 870 | 871 |
| 871 return redirect_info; | 872 return redirect_info; |
| 872 } | 873 } |
| 873 | 874 |
| 874 } // namespace net | 875 } // namespace net |
| OLD | NEW |