xref: /aosp_15_r20/external/cronet/net/http/http_request_info.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2011 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_HTTP_HTTP_REQUEST_INFO_H__
6 #define NET_HTTP_HTTP_REQUEST_INFO_H__
7 
8 #include <optional>
9 #include <string>
10 
11 #include "base/memory/raw_ptr.h"
12 #include "net/base/idempotency.h"
13 #include "net/base/net_export.h"
14 #include "net/base/network_anonymization_key.h"
15 #include "net/base/network_isolation_key.h"
16 #include "net/base/privacy_mode.h"
17 #include "net/base/request_priority.h"
18 #include "net/dns/public/secure_dns_policy.h"
19 #include "net/http/http_request_headers.h"
20 #include "net/socket/socket_tag.h"
21 #include "net/traffic_annotation/network_traffic_annotation.h"
22 #include "url/gurl.h"
23 #include "url/origin.h"
24 
25 namespace net {
26 
27 class UploadDataStream;
28 
29 struct NET_EXPORT HttpRequestInfo {
30   HttpRequestInfo();
31 
32   HttpRequestInfo(const HttpRequestInfo& other);
33   HttpRequestInfo& operator=(const HttpRequestInfo& other);
34   HttpRequestInfo(HttpRequestInfo&& other);
35   HttpRequestInfo& operator=(HttpRequestInfo&& other);
36 
37   ~HttpRequestInfo();
38 
39   bool IsConsistent() const;
40 
41   // The requested URL.
42   GURL url;
43 
44   // The method to use (GET, POST, etc.).
45   std::string method;
46 
47   // This key is used to isolate requests from different contexts in accessing
48   // shared cache.
49   NetworkIsolationKey network_isolation_key;
50 
51   // This key is used to isolate requests from different contexts in accessing
52   // shared network resources.
53   NetworkAnonymizationKey network_anonymization_key;
54 
55   // True if it is a subframe's document resource.
56   bool is_subframe_document_resource = false;
57 
58   // Any extra request headers (including User-Agent).
59   HttpRequestHeaders extra_headers;
60 
61   // Any upload data.
62   raw_ptr<UploadDataStream> upload_data_stream = nullptr;
63 
64   // Any load flags (see load_flags.h).
65   int load_flags = 0;
66 
67   // Flag that indicates if the request should be loaded concurrently with
68   // other requests of the same priority when using a protocol that supports
69   // HTTP extensible priorities (RFC 9218). Currently only HTTP/3.
70   bool priority_incremental = kDefaultPriorityIncremental;
71 
72   // If enabled, then request must be sent over connection that cannot be
73   // tracked by the server (e.g. without channel id).
74   PrivacyMode privacy_mode = PRIVACY_MODE_DISABLED;
75 
76   // Secure DNS Tag for the request.
77   SecureDnsPolicy secure_dns_policy = SecureDnsPolicy::kAllow;
78 
79   // Tag applied to all sockets used to service request.
80   SocketTag socket_tag;
81 
82   // Network traffic annotation received from URL request.
83   net::MutableNetworkTrafficAnnotationTag traffic_annotation;
84 
85   // Reporting upload nesting depth of this request.
86   //
87   // If the request is not a Reporting upload, the depth is 0.
88   //
89   // If the request is a Reporting upload, the depth is the max of the depth
90   // of the requests reported within it plus 1.
91   int reporting_upload_depth = 0;
92 
93   // This may the top frame origin associated with a request, or it may be the
94   // top frame site.  Or it may be nullptr.  Only used for histograms.
95   //
96   // TODO(https://crbug.com/1136054): Investigate migrating the one consumer of
97   // this to NetworkIsolationKey::TopFrameSite().  That gives more consistent
98   /// behavior, and may still provide useful metrics.
99   std::optional<url::Origin> possibly_top_frame_origin;
100 
101   // The frame origin associated with a request. This is used to isolate shared
102   // dictionaries between different frame origins.
103   std::optional<url::Origin> frame_origin;
104 
105   // Idempotency of the request, which determines that if it is safe to enable
106   // 0-RTT for the request. By default, 0-RTT is only enabled for safe
107   // HTTP methods, i.e., GET, HEAD, OPTIONS, and TRACE. For other methods,
108   // enabling 0-RTT may cause security issues since a network observer can
109   // replay the request. If the request has any side effects, those effects can
110   // happen multiple times. It is only safe to enable the 0-RTT if it is known
111   // that the request is idempotent.
112   net::Idempotency idempotency = net::DEFAULT_IDEMPOTENCY;
113 
114   // If not null, the value is used to evaluate whether the cache entry should
115   // be bypassed; if is null, that means the request site does not match the
116   // filter.
117   std::optional<int64_t> fps_cache_filter;
118 
119   // Use as ID to mark the cache entry when persisting. Should be a positive
120   // number once set.
121   std::optional<int64_t> browser_run_id;
122 };
123 
124 }  // namespace net
125 
126 #endif  // NET_HTTP_HTTP_REQUEST_INFO_H__
127