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