• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_UTIL_H_
6 #define NET_URL_REQUEST_REDIRECT_UTIL_H_
7 
8 #include <string>
9 #include <vector>
10 
11 #include "base/memory/scoped_refptr.h"
12 #include "net/base/net_export.h"
13 #include "third_party/abseil-cpp/absl/types/optional.h"
14 
15 class GURL;
16 
17 namespace net {
18 
19 struct RedirectInfo;
20 class HttpRequestHeaders;
21 class HttpResponseHeaders;
22 
23 class RedirectUtil {
24  public:
25   // Valid status codes for the redirect job. Other 30x codes are theoretically
26   // valid, but unused so far.  Both 302 and 307 are temporary redirects, with
27   // the difference being that 302 converts POSTs to GETs and removes upload
28   // data.
29   enum class ResponseCode {
30     REDIRECT_302_FOUND = 302,
31     REDIRECT_307_TEMPORARY_REDIRECT = 307,
32   };
33 
34   // Updates HTTP headers in |request_headers| for a redirect.
35   // |removed_headers| and |modified_headers| are specified by
36   // clients to add or override existing headers for the redirect.
37   // |should_clear_upload| is set to true when the request body should be
38   // cleared during the redirect.
39   NET_EXPORT static void UpdateHttpRequest(
40       const GURL& original_url,
41       const std::string& original_method,
42       const RedirectInfo& redirect_info,
43       const absl::optional<std::vector<std::string>>& removed_headers,
44       const absl::optional<net::HttpRequestHeaders>& modified_headers,
45       HttpRequestHeaders* request_headers,
46       bool* should_clear_upload);
47 
48   // Returns the the "normalized" value of Referrer-Policy header if available.
49   // Otherwise returns absl::nullopt.
50   NET_EXPORT static absl::optional<std::string> GetReferrerPolicyHeader(
51       const HttpResponseHeaders* response_headers);
52 
53   NET_EXPORT static scoped_refptr<HttpResponseHeaders>
54   SynthesizeRedirectHeaders(const GURL& redirect_destination,
55                             ResponseCode response_code,
56                             const std::string& redirect_reason,
57                             const HttpRequestHeaders& request_headers);
58 };
59 
60 }  // namespace net
61 
62 #endif  // NET_URL_REQUEST_REDIRECT_UTIL_H_
63