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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/metrics/histogram_macros.h" | 12 #include "base/metrics/histogram_macros.h" |
13 #include "base/power_monitor/power_monitor.h" | 13 #include "base/power_monitor/power_monitor.h" |
14 #include "base/profiler/scoped_tracker.h" | 14 #include "base/profiler/scoped_tracker.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_split.h" | |
17 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
18 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
19 #include "base/values.h" | 20 #include "base/values.h" |
20 #include "net/base/auth.h" | 21 #include "net/base/auth.h" |
21 #include "net/base/host_port_pair.h" | 22 #include "net/base/host_port_pair.h" |
22 #include "net/base/io_buffer.h" | 23 #include "net/base/io_buffer.h" |
23 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
24 #include "net/base/load_states.h" | 25 #include "net/base/load_states.h" |
25 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
26 #include "net/base/network_delegate.h" | 27 #include "net/base/network_delegate.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
55 // See: | 56 // See: |
56 // https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#section-7.3 | 57 // https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#section-7.3 |
57 if ((http_status_code == 303 && method != "HEAD") || | 58 if ((http_status_code == 303 && method != "HEAD") || |
58 ((http_status_code == 301 || http_status_code == 302) && | 59 ((http_status_code == 301 || http_status_code == 302) && |
59 method == "POST")) { | 60 method == "POST")) { |
60 return "GET"; | 61 return "GET"; |
61 } | 62 } |
62 return method; | 63 return method; |
63 } | 64 } |
64 | 65 |
66 // A redirect response can contain a Referrer-Policy header | |
67 // (https://w3c.github.io/webappsec-referrer-policy/). This function | |
68 // checks for a Referrer-Policy header, and parses it if | |
69 // present. Returns the referrer policy that should be used for the | |
70 // request. | |
71 URLRequest::ReferrerPolicy ProcessReferrerPolicyHeaderOnRedirect( | |
72 URLRequest* request) { | |
73 URLRequest::ReferrerPolicy new_policy = request->referrer_policy(); | |
74 | |
75 std::string referrer_policy_header; | |
76 request->GetResponseHeaderByName("Referrer-Policy", &referrer_policy_header); | |
77 std::vector<std::string> policy_tokens = | |
78 base::SplitString(referrer_policy_header, ",", base::TRIM_WHITESPACE, | |
79 base::SPLIT_WANT_NONEMPTY); | |
80 | |
81 for (const auto& token : policy_tokens) { | |
82 if (base::CompareCaseInsensitiveASCII(token, "never") == 0 || | |
83 base::CompareCaseInsensitiveASCII(token, "no-referrer") == 0) { | |
84 new_policy = URLRequest::NO_REFERRER; | |
mmenke
2016/06/28 21:32:08
Should probably have continues after all of these,
estark
2016/06/28 22:38:42
Done.
| |
85 } | |
86 | |
87 if (base::CompareCaseInsensitiveASCII(token, "default") == 0 || | |
88 base::CompareCaseInsensitiveASCII(token, | |
89 "no-referrer-when-downgrade") == 0) { | |
90 new_policy = | |
91 URLRequest::CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE; | |
92 } | |
93 | |
94 if (base::CompareCaseInsensitiveASCII(token, "origin") == 0) { | |
95 new_policy = URLRequest::ORIGIN; | |
96 } | |
97 | |
98 if (base::CompareCaseInsensitiveASCII(token, "origin-when-cross-origin") == | |
99 0) { | |
100 new_policy = URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN; | |
101 } | |
102 | |
103 if (base::CompareCaseInsensitiveASCII(token, "always") == 0 || | |
104 base::CompareCaseInsensitiveASCII(token, "unsafe-url") == 0) { | |
105 new_policy = URLRequest::NEVER_CLEAR_REFERRER; | |
106 } | |
107 } | |
108 return new_policy; | |
109 } | |
110 | |
65 } // namespace | 111 } // namespace |
66 | 112 |
67 URLRequestJob::URLRequestJob(URLRequest* request, | 113 URLRequestJob::URLRequestJob(URLRequest* request, |
68 NetworkDelegate* network_delegate) | 114 NetworkDelegate* network_delegate) |
69 : request_(request), | 115 : request_(request), |
70 done_(false), | 116 done_(false), |
71 prefilter_bytes_read_(0), | 117 prefilter_bytes_read_(0), |
72 postfilter_bytes_read_(0), | 118 postfilter_bytes_read_(0), |
73 filter_needs_more_output_space_(false), | 119 filter_needs_more_output_space_(false), |
74 filtered_read_buffer_len_(0), | 120 filtered_read_buffer_len_(0), |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 return GURL(); | 383 return GURL(); |
338 } else { | 384 } else { |
339 return original_referrer.GetOrigin(); | 385 return original_referrer.GetOrigin(); |
340 } | 386 } |
341 | 387 |
342 case URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN: | 388 case URLRequest::ORIGIN_ONLY_ON_TRANSITION_CROSS_ORIGIN: |
343 return same_origin ? original_referrer : original_referrer.GetOrigin(); | 389 return same_origin ? original_referrer : original_referrer.GetOrigin(); |
344 | 390 |
345 case URLRequest::NEVER_CLEAR_REFERRER: | 391 case URLRequest::NEVER_CLEAR_REFERRER: |
346 return original_referrer; | 392 return original_referrer; |
393 case URLRequest::ORIGIN: | |
394 return original_referrer.GetOrigin(); | |
395 case URLRequest::NO_REFERRER: | |
396 return GURL(); | |
397 case URLRequest::MAX_REFERRER_POLICY: | |
mmenke
2016/06/28 21:32:08
I'm fine with adding this, if it's useful, but why
estark
2016/06/28 22:38:42
RedirectInfo is sent in IPCs, and adding a Referre
| |
398 NOTREACHED(); | |
399 return original_referrer; | |
mmenke
2016/06/28 21:32:08
This should probably be GURL(), to match the fallt
estark
2016/06/28 22:38:42
Done.
| |
347 } | 400 } |
348 | 401 |
349 NOTREACHED(); | 402 NOTREACHED(); |
350 return GURL(); | 403 return GURL(); |
351 } | 404 } |
352 | 405 |
353 void URLRequestJob::NotifyCertificateRequested( | 406 void URLRequestJob::NotifyCertificateRequested( |
354 SSLCertRequestInfo* cert_request_info) { | 407 SSLCertRequestInfo* cert_request_info) { |
355 request_->NotifyCertificateRequested(cert_request_info); | 408 request_->NotifyCertificateRequested(cert_request_info); |
356 } | 409 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
391 // the time stamps if it has that information. The default request_time is | 444 // the time stamps if it has that information. The default request_time is |
392 // set by URLRequest before it calls our Start method. | 445 // set by URLRequest before it calls our Start method. |
393 request_->response_info_.response_time = base::Time::Now(); | 446 request_->response_info_.response_time = base::Time::Now(); |
394 GetResponseInfo(&request_->response_info_); | 447 GetResponseInfo(&request_->response_info_); |
395 | 448 |
396 MaybeNotifyNetworkBytes(); | 449 MaybeNotifyNetworkBytes(); |
397 request_->OnHeadersComplete(); | 450 request_->OnHeadersComplete(); |
398 | 451 |
399 GURL new_location; | 452 GURL new_location; |
400 int http_status_code; | 453 int http_status_code; |
454 | |
401 if (IsRedirectResponse(&new_location, &http_status_code)) { | 455 if (IsRedirectResponse(&new_location, &http_status_code)) { |
402 // Redirect response bodies are not read. Notify the transaction | 456 // Redirect response bodies are not read. Notify the transaction |
403 // so it does not treat being stopped as an error. | 457 // so it does not treat being stopped as an error. |
404 DoneReadingRedirectResponse(); | 458 DoneReadingRedirectResponse(); |
405 | 459 |
406 // When notifying the URLRequest::Delegate, it can destroy the request, | 460 // When notifying the URLRequest::Delegate, it can destroy the request, |
407 // which will destroy |this|. After calling to the URLRequest::Delegate, | 461 // which will destroy |this|. After calling to the URLRequest::Delegate, |
408 // pointer must be checked to see if |this| still exists, and if not, the | 462 // pointer must be checked to see if |this| still exists, and if not, the |
409 // code must return immediately. | 463 // code must return immediately. |
410 base::WeakPtr<URLRequestJob> weak_this(weak_factory_.GetWeakPtr()); | 464 base::WeakPtr<URLRequestJob> weak_this(weak_factory_.GetWeakPtr()); |
(...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
937 | 991 |
938 // Update the first-party URL if appropriate. | 992 // Update the first-party URL if appropriate. |
939 if (request_->first_party_url_policy() == | 993 if (request_->first_party_url_policy() == |
940 URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT) { | 994 URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT) { |
941 redirect_info.new_first_party_for_cookies = redirect_info.new_url; | 995 redirect_info.new_first_party_for_cookies = redirect_info.new_url; |
942 } else { | 996 } else { |
943 redirect_info.new_first_party_for_cookies = | 997 redirect_info.new_first_party_for_cookies = |
944 request_->first_party_for_cookies(); | 998 request_->first_party_for_cookies(); |
945 } | 999 } |
946 | 1000 |
1001 if (request_->context()->enable_referrer_policy_header()) { | |
1002 redirect_info.new_referrer_policy = | |
1003 ProcessReferrerPolicyHeaderOnRedirect(request_); | |
1004 } else { | |
1005 redirect_info.new_referrer_policy = request_->referrer_policy(); | |
1006 } | |
1007 | |
947 // Alter the referrer if redirecting cross-origin (especially HTTP->HTTPS). | 1008 // Alter the referrer if redirecting cross-origin (especially HTTP->HTTPS). |
948 redirect_info.new_referrer = | 1009 redirect_info.new_referrer = |
949 ComputeReferrerForRedirect(request_->referrer_policy(), | 1010 ComputeReferrerForRedirect(redirect_info.new_referrer_policy, |
950 request_->referrer(), | 1011 request_->referrer(), redirect_info.new_url) |
951 redirect_info.new_url).spec(); | 1012 .spec(); |
952 | 1013 |
953 std::string include_referer; | 1014 std::string include_referer; |
954 request_->GetResponseHeaderByName("include-referer-token-binding-id", | 1015 request_->GetResponseHeaderByName("include-referer-token-binding-id", |
955 &include_referer); | 1016 &include_referer); |
956 if (include_referer == "true" && | 1017 if (include_referer == "true" && |
957 request_->ssl_info().token_binding_negotiated) { | 1018 request_->ssl_info().token_binding_negotiated) { |
958 redirect_info.referred_token_binding_host = url.host(); | 1019 redirect_info.referred_token_binding_host = url.host(); |
959 } | 1020 } |
960 | 1021 |
961 return redirect_info; | 1022 return redirect_info; |
(...skipping 16 matching lines...) Expand all Loading... | |
978 int64_t total_sent_bytes = GetTotalSentBytes(); | 1039 int64_t total_sent_bytes = GetTotalSentBytes(); |
979 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); | 1040 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); |
980 if (total_sent_bytes > last_notified_total_sent_bytes_) { | 1041 if (total_sent_bytes > last_notified_total_sent_bytes_) { |
981 network_delegate_->NotifyNetworkBytesSent( | 1042 network_delegate_->NotifyNetworkBytesSent( |
982 request_, total_sent_bytes - last_notified_total_sent_bytes_); | 1043 request_, total_sent_bytes - last_notified_total_sent_bytes_); |
983 } | 1044 } |
984 last_notified_total_sent_bytes_ = total_sent_bytes; | 1045 last_notified_total_sent_bytes_ = total_sent_bytes; |
985 } | 1046 } |
986 | 1047 |
987 } // namespace net | 1048 } // namespace net |
OLD | NEW |