1 // Copyright 2014 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_URL_REQUEST_REDIRECT_INFO_H_ 6 #define NET_URL_REQUEST_REDIRECT_INFO_H_ 7 8 #include <optional> 9 #include <string> 10 11 #include "base/time/time.h" 12 #include "net/base/net_export.h" 13 #include "net/cookies/site_for_cookies.h" 14 #include "net/url_request/referrer_policy.h" 15 #include "url/gurl.h" 16 17 namespace net { 18 19 // RedirectInfo captures information about a redirect and any fields in a 20 // request that change. 21 struct NET_EXPORT RedirectInfo { 22 // First-party URL redirect policy: During server redirects, the first-party 23 // URL for cookies normally doesn't change. However, if the request is a 24 // top-level first-party request, the first-party URL should be updated to the 25 // URL on every redirect. 26 enum class FirstPartyURLPolicy { 27 NEVER_CHANGE_URL, 28 UPDATE_URL_ON_REDIRECT, 29 }; 30 31 RedirectInfo(); 32 RedirectInfo(const RedirectInfo& other); 33 ~RedirectInfo(); 34 35 // Computes a new RedirectInfo. 36 static RedirectInfo ComputeRedirectInfo( 37 // The following arguments |original_*| are the properties of the original 38 // request. 39 const std::string& original_method, 40 const GURL& original_url, 41 const SiteForCookies& original_site_for_cookies, 42 FirstPartyURLPolicy original_first_party_url_policy, 43 ReferrerPolicy original_referrer_policy, 44 const std::string& original_referrer, 45 // The HTTP status code of the redirect response. 46 int http_status_code, 47 // The new location URL of the redirect response. 48 const GURL& new_location, 49 // Referrer-Policy header of the redirect response. 50 const std::optional<std::string>& referrer_policy_header, 51 // Whether the URL was upgraded to HTTPS due to upgrade-insecure-requests. 52 bool insecure_scheme_was_upgraded, 53 // This method copies the URL fragment of the original URL to the new URL 54 // by default. Set false only when the network delegate has set the 55 // desired redirect URL (with or without fragment), so it must not be 56 // changed any more. 57 bool copy_fragment = true, 58 // Whether the redirect is caused by a failure of signed exchange loading. 59 bool is_signed_exchange_fallback_redirect = false); 60 61 // The status code for the redirect response. This is almost redundant with 62 // the response headers, but some URLRequestJobs emit redirects without 63 // headers. 64 int status_code = -1; 65 66 // The new request method. Depending on the response code, the request method 67 // may change. 68 std::string new_method; 69 70 // The new request URL. 71 GURL new_url; 72 73 // The new first-party for cookies. 74 SiteForCookies new_site_for_cookies; 75 76 // The new HTTP referrer header. 77 std::string new_referrer; 78 79 // True if this redirect was upgraded to HTTPS due to the 80 // upgrade-insecure-requests policy. 81 bool insecure_scheme_was_upgraded = false; 82 83 // True if this is a redirect from Signed Exchange to its fallback URL. 84 bool is_signed_exchange_fallback_redirect = false; 85 86 // The new referrer policy that should be obeyed if there are 87 // subsequent redirects. 88 ReferrerPolicy new_referrer_policy = 89 ReferrerPolicy::CLEAR_ON_TRANSITION_FROM_SECURE_TO_INSECURE; 90 91 // When navigation is restarted due to a Critical-CH header this stores the 92 // time at which the the restart was initiated. 93 base::TimeTicks critical_ch_restart_time; 94 }; 95 96 } // namespace net 97 98 #endif // NET_URL_REQUEST_REDIRECT_INFO_H_ 99