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

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

Issue 935333002: Update from https://crrev.com/316786 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | net/websockets/websocket_stream.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) 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 {
25
24 namespace { 26 namespace {
25 27
26 // Callback for TYPE_URL_REQUEST_FILTERS_SET net-internals event. 28 // Callback for TYPE_URL_REQUEST_FILTERS_SET net-internals event.
27 base::Value* FiltersSetCallback(net::Filter* filter, 29 base::Value* FiltersSetCallback(Filter* filter,
28 enum net::NetLog::LogLevel /* log_level */) { 30 NetLog::LogLevel /* log_level */) {
29 base::DictionaryValue* event_params = new base::DictionaryValue(); 31 base::DictionaryValue* event_params = new base::DictionaryValue();
30 event_params->SetString("filters", filter->OrderedFilterList()); 32 event_params->SetString("filters", filter->OrderedFilterList());
31 return event_params; 33 return event_params;
32 } 34 }
33 35
36 std::string ComputeMethodForRedirect(const std::string& method,
37 int http_status_code) {
38 // 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 // 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 // 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 // so shall we.
45 // See:
46 // https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#section-7.3
47 if ((http_status_code == 303 && method != "HEAD") ||
48 ((http_status_code == 301 || http_status_code == 302) &&
49 method == "POST")) {
50 return "GET";
51 }
52 return method;
53 }
54
34 } // namespace 55 } // namespace
35 56
36 namespace net {
37
38 URLRequestJob::URLRequestJob(URLRequest* request, 57 URLRequestJob::URLRequestJob(URLRequest* request,
39 NetworkDelegate* network_delegate) 58 NetworkDelegate* network_delegate)
40 : request_(request), 59 : request_(request),
41 done_(false), 60 done_(false),
42 prefilter_bytes_read_(0), 61 prefilter_bytes_read_(0),
43 postfilter_bytes_read_(0), 62 postfilter_bytes_read_(0),
44 filter_input_byte_count_(0), 63 filter_input_byte_count_(0),
45 filter_needs_more_output_space_(false), 64 filter_needs_more_output_space_(false),
46 filtered_read_buffer_len_(0), 65 filtered_read_buffer_len_(0),
47 has_handled_response_(false), 66 has_handled_response_(false),
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 919
901 RedirectInfo URLRequestJob::ComputeRedirectInfo(const GURL& location, 920 RedirectInfo URLRequestJob::ComputeRedirectInfo(const GURL& location,
902 int http_status_code) { 921 int http_status_code) {
903 const GURL& url = request_->url(); 922 const GURL& url = request_->url();
904 923
905 RedirectInfo redirect_info; 924 RedirectInfo redirect_info;
906 925
907 redirect_info.status_code = http_status_code; 926 redirect_info.status_code = http_status_code;
908 927
909 // The request method may change, depending on the status code. 928 // The request method may change, depending on the status code.
910 redirect_info.new_method = URLRequest::ComputeMethodForRedirect( 929 redirect_info.new_method =
911 request_->method(), http_status_code); 930 ComputeMethodForRedirect(request_->method(), http_status_code);
912 931
913 // Move the reference fragment of the old location to the new one if the 932 // Move the reference fragment of the old location to the new one if the
914 // new one has none. This duplicates mozilla's behavior. 933 // new one has none. This duplicates mozilla's behavior.
915 if (url.is_valid() && url.has_ref() && !location.has_ref() && 934 if (url.is_valid() && url.has_ref() && !location.has_ref() &&
916 CopyFragmentOnRedirect(location)) { 935 CopyFragmentOnRedirect(location)) {
917 GURL::Replacements replacements; 936 GURL::Replacements replacements;
918 // Reference the |ref| directly out of the original URL to avoid a 937 // Reference the |ref| directly out of the original URL to avoid a
919 // malloc. 938 // malloc.
920 replacements.SetRef(url.spec().data(), 939 replacements.SetRef(url.spec().data(),
921 url.parsed_for_possibly_invalid_spec().ref); 940 url.parsed_for_possibly_invalid_spec().ref);
(...skipping 14 matching lines...) Expand all
936 // Alter the referrer if redirecting cross-origin (especially HTTP->HTTPS). 955 // Alter the referrer if redirecting cross-origin (especially HTTP->HTTPS).
937 redirect_info.new_referrer = 956 redirect_info.new_referrer =
938 ComputeReferrerForRedirect(request_->referrer_policy(), 957 ComputeReferrerForRedirect(request_->referrer_policy(),
939 request_->referrer(), 958 request_->referrer(),
940 redirect_info.new_url).spec(); 959 redirect_info.new_url).spec();
941 960
942 return redirect_info; 961 return redirect_info;
943 } 962 }
944 963
945 } // namespace net 964 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | net/websockets/websocket_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698