redirect_util.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef NET_URL_REQUEST_REDIRECT_UTIL_H_
  5. #define NET_URL_REQUEST_REDIRECT_UTIL_H_
  6. #include <string>
  7. #include <vector>
  8. #include "base/memory/scoped_refptr.h"
  9. #include "net/base/net_export.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. class GURL;
  12. namespace net {
  13. struct RedirectInfo;
  14. class HttpRequestHeaders;
  15. class HttpResponseHeaders;
  16. class RedirectUtil {
  17. public:
  18. // Valid status codes for the redirect job. Other 30x codes are theoretically
  19. // valid, but unused so far. Both 302 and 307 are temporary redirects, with
  20. // the difference being that 302 converts POSTs to GETs and removes upload
  21. // data.
  22. enum class ResponseCode {
  23. REDIRECT_302_FOUND = 302,
  24. REDIRECT_307_TEMPORARY_REDIRECT = 307,
  25. };
  26. // Updates HTTP headers in |request_headers| for a redirect.
  27. // |removed_headers| and |modified_headers| are specified by
  28. // clients to add or override existing headers for the redirect.
  29. // |should_clear_upload| is set to true when the request body should be
  30. // cleared during the redirect.
  31. NET_EXPORT static void UpdateHttpRequest(
  32. const GURL& original_url,
  33. const std::string& original_method,
  34. const RedirectInfo& redirect_info,
  35. const absl::optional<std::vector<std::string>>& removed_headers,
  36. const absl::optional<net::HttpRequestHeaders>& modified_headers,
  37. HttpRequestHeaders* request_headers,
  38. bool* should_clear_upload);
  39. // Returns the the "normalized" value of Referrer-Policy header if available.
  40. // Otherwise returns absl::nullopt.
  41. NET_EXPORT static absl::optional<std::string> GetReferrerPolicyHeader(
  42. const HttpResponseHeaders* response_headers);
  43. NET_EXPORT static scoped_refptr<HttpResponseHeaders>
  44. SynthesizeRedirectHeaders(const GURL& redirect_destination,
  45. ResponseCode response_code,
  46. const std::string& redirect_reason,
  47. const HttpRequestHeaders& request_headers);
  48. };
  49. } // namespace net
  50. #endif // NET_URL_REQUEST_REDIRECT_UTIL_H_