xref: /aosp_15_r20/external/cronet/net/http/http_response_info.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Copyright 2011 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker // found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker 
5*6777b538SAndroid Build Coastguard Worker #ifndef NET_HTTP_HTTP_RESPONSE_INFO_H_
6*6777b538SAndroid Build Coastguard Worker #define NET_HTTP_HTTP_RESPONSE_INFO_H_
7*6777b538SAndroid Build Coastguard Worker 
8*6777b538SAndroid Build Coastguard Worker #include <optional>
9*6777b538SAndroid Build Coastguard Worker #include <set>
10*6777b538SAndroid Build Coastguard Worker #include <string>
11*6777b538SAndroid Build Coastguard Worker 
12*6777b538SAndroid Build Coastguard Worker #include "base/time/time.h"
13*6777b538SAndroid Build Coastguard Worker #include "net/base/auth.h"
14*6777b538SAndroid Build Coastguard Worker #include "net/base/ip_endpoint.h"
15*6777b538SAndroid Build Coastguard Worker #include "net/base/net_export.h"
16*6777b538SAndroid Build Coastguard Worker #include "net/base/proxy_chain.h"
17*6777b538SAndroid Build Coastguard Worker #include "net/dns/public/resolve_error_info.h"
18*6777b538SAndroid Build Coastguard Worker #include "net/http/alternate_protocol_usage.h"
19*6777b538SAndroid Build Coastguard Worker #include "net/http/http_connection_info.h"
20*6777b538SAndroid Build Coastguard Worker #include "net/http/http_vary_data.h"
21*6777b538SAndroid Build Coastguard Worker #include "net/ssl/ssl_info.h"
22*6777b538SAndroid Build Coastguard Worker 
23*6777b538SAndroid Build Coastguard Worker namespace base {
24*6777b538SAndroid Build Coastguard Worker class Pickle;
25*6777b538SAndroid Build Coastguard Worker }
26*6777b538SAndroid Build Coastguard Worker 
27*6777b538SAndroid Build Coastguard Worker namespace net {
28*6777b538SAndroid Build Coastguard Worker 
29*6777b538SAndroid Build Coastguard Worker class HttpResponseHeaders;
30*6777b538SAndroid Build Coastguard Worker class SSLCertRequestInfo;
31*6777b538SAndroid Build Coastguard Worker 
32*6777b538SAndroid Build Coastguard Worker class NET_EXPORT HttpResponseInfo {
33*6777b538SAndroid Build Coastguard Worker  public:
34*6777b538SAndroid Build Coastguard Worker   // Used for categorizing transactions for reporting in histograms.
35*6777b538SAndroid Build Coastguard Worker   // CacheEntryStatus covers relatively common use cases being measured and
36*6777b538SAndroid Build Coastguard Worker   // considered for optimization. Many use cases that are more complex or
37*6777b538SAndroid Build Coastguard Worker   // uncommon are binned as OTHER, and details are not reported.
38*6777b538SAndroid Build Coastguard Worker   // NOTE: This enumeration is used in histograms, so please do not add entries
39*6777b538SAndroid Build Coastguard Worker   // in the middle.
40*6777b538SAndroid Build Coastguard Worker   enum CacheEntryStatus {
41*6777b538SAndroid Build Coastguard Worker     ENTRY_UNDEFINED,
42*6777b538SAndroid Build Coastguard Worker     // Complex or uncommon case. E.g., auth (401), partial responses (206), ...
43*6777b538SAndroid Build Coastguard Worker     ENTRY_OTHER,
44*6777b538SAndroid Build Coastguard Worker     // The response was not in the cache. Implies !was_cached &&
45*6777b538SAndroid Build Coastguard Worker     // network_accessed.
46*6777b538SAndroid Build Coastguard Worker     ENTRY_NOT_IN_CACHE,
47*6777b538SAndroid Build Coastguard Worker     // The response was served from the cache and no validation was needed.
48*6777b538SAndroid Build Coastguard Worker     // Implies was_cached && !network_accessed.
49*6777b538SAndroid Build Coastguard Worker     ENTRY_USED,
50*6777b538SAndroid Build Coastguard Worker     // The response was validated and served from the cache. Implies was_cached
51*6777b538SAndroid Build Coastguard Worker     // && network_accessed.
52*6777b538SAndroid Build Coastguard Worker     ENTRY_VALIDATED,
53*6777b538SAndroid Build Coastguard Worker     // There was a stale entry in the cache that was updated. Implies
54*6777b538SAndroid Build Coastguard Worker     // !was_cached && network_accessed.
55*6777b538SAndroid Build Coastguard Worker     ENTRY_UPDATED,
56*6777b538SAndroid Build Coastguard Worker     // The HTTP request didn't allow a conditional request. Implies !was_cached
57*6777b538SAndroid Build Coastguard Worker     // && network_accessed.
58*6777b538SAndroid Build Coastguard Worker     ENTRY_CANT_CONDITIONALIZE,
59*6777b538SAndroid Build Coastguard Worker     ENTRY_MAX,
60*6777b538SAndroid Build Coastguard Worker   };
61*6777b538SAndroid Build Coastguard Worker 
62*6777b538SAndroid Build Coastguard Worker   HttpResponseInfo();
63*6777b538SAndroid Build Coastguard Worker   HttpResponseInfo(const HttpResponseInfo& rhs);
64*6777b538SAndroid Build Coastguard Worker   ~HttpResponseInfo();
65*6777b538SAndroid Build Coastguard Worker   HttpResponseInfo& operator=(const HttpResponseInfo& rhs);
66*6777b538SAndroid Build Coastguard Worker   // Even though we could get away with the copy ctor and default operator=,
67*6777b538SAndroid Build Coastguard Worker   // that would prevent us from doing a bunch of forward declaration.
68*6777b538SAndroid Build Coastguard Worker 
69*6777b538SAndroid Build Coastguard Worker   // Initializes from the representation stored in the given pickle.
70*6777b538SAndroid Build Coastguard Worker   bool InitFromPickle(const base::Pickle& pickle, bool* response_truncated);
71*6777b538SAndroid Build Coastguard Worker 
72*6777b538SAndroid Build Coastguard Worker   // Call this method to persist the response info.
73*6777b538SAndroid Build Coastguard Worker   void Persist(base::Pickle* pickle,
74*6777b538SAndroid Build Coastguard Worker                bool skip_transient_headers,
75*6777b538SAndroid Build Coastguard Worker                bool response_truncated) const;
76*6777b538SAndroid Build Coastguard Worker 
77*6777b538SAndroid Build Coastguard Worker   // Whether QUIC is used or not.
78*6777b538SAndroid Build Coastguard Worker   bool DidUseQuic() const;
79*6777b538SAndroid Build Coastguard Worker 
80*6777b538SAndroid Build Coastguard Worker   // The following is only defined if the request_time member is set.
81*6777b538SAndroid Build Coastguard Worker   // If this resource was found in the cache, then this bool is set, and
82*6777b538SAndroid Build Coastguard Worker   // request_time may corresponds to a time "far" in the past.  Note that
83*6777b538SAndroid Build Coastguard Worker   // stale content (perhaps un-cacheable) may be fetched from cache subject to
84*6777b538SAndroid Build Coastguard Worker   // the load flags specified on the request info.  For example, this is done
85*6777b538SAndroid Build Coastguard Worker   // when a user presses the back button to re-render pages, or at startup,
86*6777b538SAndroid Build Coastguard Worker   // when reloading previously visited pages (without going over the network).
87*6777b538SAndroid Build Coastguard Worker   // Note also that under normal circumstances, was_cached is set to the correct
88*6777b538SAndroid Build Coastguard Worker   // value even if the request fails.
89*6777b538SAndroid Build Coastguard Worker   bool was_cached = false;
90*6777b538SAndroid Build Coastguard Worker 
91*6777b538SAndroid Build Coastguard Worker   // How this response was handled by the HTTP cache.
92*6777b538SAndroid Build Coastguard Worker   CacheEntryStatus cache_entry_status = CacheEntryStatus::ENTRY_UNDEFINED;
93*6777b538SAndroid Build Coastguard Worker 
94*6777b538SAndroid Build Coastguard Worker   // True if the request accessed the network in the process of retrieving
95*6777b538SAndroid Build Coastguard Worker   // data.
96*6777b538SAndroid Build Coastguard Worker   bool network_accessed = false;
97*6777b538SAndroid Build Coastguard Worker 
98*6777b538SAndroid Build Coastguard Worker   // True if the request was fetched over a SPDY channel.
99*6777b538SAndroid Build Coastguard Worker   bool was_fetched_via_spdy = false;
100*6777b538SAndroid Build Coastguard Worker 
101*6777b538SAndroid Build Coastguard Worker   // True if ALPN was negotiated for this request.
102*6777b538SAndroid Build Coastguard Worker   bool was_alpn_negotiated = false;
103*6777b538SAndroid Build Coastguard Worker 
104*6777b538SAndroid Build Coastguard Worker   // True if the response was fetched via explicit proxying. Any type of
105*6777b538SAndroid Build Coastguard Worker   // proxying may have taken place, HTTP or SOCKS. Note, we do not know if a
106*6777b538SAndroid Build Coastguard Worker   // transparent proxy may have been involved.
107*6777b538SAndroid Build Coastguard Worker   //
108*6777b538SAndroid Build Coastguard Worker   // If true and this struct was not restored from pickled data, `proxy_chain`
109*6777b538SAndroid Build Coastguard Worker   // contains the proxy chain that was used.
110*6777b538SAndroid Build Coastguard Worker   //
111*6777b538SAndroid Build Coastguard Worker   // TODO(https://crbug.com/653354): Remove this in favor of `proxy_chain`.
112*6777b538SAndroid Build Coastguard Worker   bool was_fetched_via_proxy = false;
113*6777b538SAndroid Build Coastguard Worker 
114*6777b538SAndroid Build Coastguard Worker   // Information about the proxy chain used to fetch this response, if any.
115*6777b538SAndroid Build Coastguard Worker   //
116*6777b538SAndroid Build Coastguard Worker   // This field is not persisted by `Persist()` and not restored by
117*6777b538SAndroid Build Coastguard Worker   // `InitFromPickle()`.
118*6777b538SAndroid Build Coastguard Worker   //
119*6777b538SAndroid Build Coastguard Worker   // TODO(https://crbug.com/653354): Support this field in `Persist()` and
120*6777b538SAndroid Build Coastguard Worker   // `InitFromPickle()` then use it to replace `was_fetched_via_proxy`.
121*6777b538SAndroid Build Coastguard Worker   ProxyChain proxy_chain;
122*6777b538SAndroid Build Coastguard Worker 
123*6777b538SAndroid Build Coastguard Worker   // Whether this request was eligible for IP Protection based on the request
124*6777b538SAndroid Build Coastguard Worker   // being a match to the masked domain list, if available.
125*6777b538SAndroid Build Coastguard Worker   // This field is not persisted by `Persist()` and not restored by
126*6777b538SAndroid Build Coastguard Worker   // `InitFromPickle()`.
127*6777b538SAndroid Build Coastguard Worker   bool was_mdl_match = false;
128*6777b538SAndroid Build Coastguard Worker 
129*6777b538SAndroid Build Coastguard Worker   // Whether the request use http proxy or server authentication.
130*6777b538SAndroid Build Coastguard Worker   bool did_use_http_auth = false;
131*6777b538SAndroid Build Coastguard Worker 
132*6777b538SAndroid Build Coastguard Worker   // True if the resource was originally fetched for a prefetch and has not been
133*6777b538SAndroid Build Coastguard Worker   // used since.
134*6777b538SAndroid Build Coastguard Worker   bool unused_since_prefetch = false;
135*6777b538SAndroid Build Coastguard Worker 
136*6777b538SAndroid Build Coastguard Worker   // True if the response is a prefetch whose reuse is "restricted". This means
137*6777b538SAndroid Build Coastguard Worker   // it can only be reused from the cache by requests that are marked as able to
138*6777b538SAndroid Build Coastguard Worker   // use restricted prefetches.
139*6777b538SAndroid Build Coastguard Worker   bool restricted_prefetch = false;
140*6777b538SAndroid Build Coastguard Worker 
141*6777b538SAndroid Build Coastguard Worker   // True if this resource is stale and needs async revalidation.
142*6777b538SAndroid Build Coastguard Worker   // This value is not persisted by Persist(); it is only ever set when the
143*6777b538SAndroid Build Coastguard Worker   // response is retrieved from the cache.
144*6777b538SAndroid Build Coastguard Worker   bool async_revalidation_requested = false;
145*6777b538SAndroid Build Coastguard Worker 
146*6777b538SAndroid Build Coastguard Worker   // stale-while-revalidate, if any, will be honored until time given by
147*6777b538SAndroid Build Coastguard Worker   // |stale_revalidate_timeout|. This value is latched the first time
148*6777b538SAndroid Build Coastguard Worker   // stale-while-revalidate is used until the resource is revalidated.
149*6777b538SAndroid Build Coastguard Worker   base::Time stale_revalidate_timeout;
150*6777b538SAndroid Build Coastguard Worker 
151*6777b538SAndroid Build Coastguard Worker   // Remote address of the socket which fetched this resource.
152*6777b538SAndroid Build Coastguard Worker   //
153*6777b538SAndroid Build Coastguard Worker   // NOTE: If the response was served from the cache (was_cached is true),
154*6777b538SAndroid Build Coastguard Worker   // the socket address will be set to the address that the content came from
155*6777b538SAndroid Build Coastguard Worker   // originally.  This is true even if the response was re-validated using a
156*6777b538SAndroid Build Coastguard Worker   // different remote address, or if some of the content came from a byte-range
157*6777b538SAndroid Build Coastguard Worker   // request to a different address.
158*6777b538SAndroid Build Coastguard Worker   IPEndPoint remote_endpoint;
159*6777b538SAndroid Build Coastguard Worker 
160*6777b538SAndroid Build Coastguard Worker   // Protocol negotiated with the server.
161*6777b538SAndroid Build Coastguard Worker   std::string alpn_negotiated_protocol;
162*6777b538SAndroid Build Coastguard Worker 
163*6777b538SAndroid Build Coastguard Worker   // The reason why Chrome uses a specific transport protocol for HTTP
164*6777b538SAndroid Build Coastguard Worker   // semantics.
165*6777b538SAndroid Build Coastguard Worker   net::AlternateProtocolUsage alternate_protocol_usage =
166*6777b538SAndroid Build Coastguard Worker       net::AlternateProtocolUsage::ALTERNATE_PROTOCOL_USAGE_UNSPECIFIED_REASON;
167*6777b538SAndroid Build Coastguard Worker 
168*6777b538SAndroid Build Coastguard Worker   // The type of connection used for this response.
169*6777b538SAndroid Build Coastguard Worker   HttpConnectionInfo connection_info = HttpConnectionInfo::kUNKNOWN;
170*6777b538SAndroid Build Coastguard Worker 
171*6777b538SAndroid Build Coastguard Worker   // The time at which the request was made that resulted in this response.
172*6777b538SAndroid Build Coastguard Worker   // For cached responses, this is the last time the cache entry was validated.
173*6777b538SAndroid Build Coastguard Worker   base::Time request_time;
174*6777b538SAndroid Build Coastguard Worker 
175*6777b538SAndroid Build Coastguard Worker   // The time at which the response headers were received.  For cached
176*6777b538SAndroid Build Coastguard Worker   // this is the last time the cache entry was validated.
177*6777b538SAndroid Build Coastguard Worker   base::Time response_time;
178*6777b538SAndroid Build Coastguard Worker 
179*6777b538SAndroid Build Coastguard Worker   // Host resolution error info.
180*6777b538SAndroid Build Coastguard Worker   ResolveErrorInfo resolve_error_info;
181*6777b538SAndroid Build Coastguard Worker 
182*6777b538SAndroid Build Coastguard Worker   // If the response headers indicate a 401 or 407 failure, then this structure
183*6777b538SAndroid Build Coastguard Worker   // will contain additional information about the authentication challenge.
184*6777b538SAndroid Build Coastguard Worker   std::optional<AuthChallengeInfo> auth_challenge;
185*6777b538SAndroid Build Coastguard Worker 
186*6777b538SAndroid Build Coastguard Worker   // The SSL client certificate request info.
187*6777b538SAndroid Build Coastguard Worker   // TODO(wtc): does this really belong in HttpResponseInfo?  I put it here
188*6777b538SAndroid Build Coastguard Worker   // because it is similar to |auth_challenge|, but unlike HTTP authentication
189*6777b538SAndroid Build Coastguard Worker   // challenge, client certificate request is not part of an HTTP response.
190*6777b538SAndroid Build Coastguard Worker   scoped_refptr<SSLCertRequestInfo> cert_request_info;
191*6777b538SAndroid Build Coastguard Worker 
192*6777b538SAndroid Build Coastguard Worker   // The SSL connection info (if HTTPS). Note that when a response is
193*6777b538SAndroid Build Coastguard Worker   // served from cache, not every field is present. See
194*6777b538SAndroid Build Coastguard Worker   // HttpResponseInfo::InitFromPickle().
195*6777b538SAndroid Build Coastguard Worker   SSLInfo ssl_info;
196*6777b538SAndroid Build Coastguard Worker 
197*6777b538SAndroid Build Coastguard Worker   // The parsed response headers and status line.
198*6777b538SAndroid Build Coastguard Worker   scoped_refptr<HttpResponseHeaders> headers;
199*6777b538SAndroid Build Coastguard Worker 
200*6777b538SAndroid Build Coastguard Worker   // The "Vary" header data for this response.
201*6777b538SAndroid Build Coastguard Worker   // Initialized and used by HttpCache::Transaction. May also be passed to an
202*6777b538SAndroid Build Coastguard Worker   // auxiliary in-memory cache in the network service.
203*6777b538SAndroid Build Coastguard Worker   HttpVaryData vary_data;
204*6777b538SAndroid Build Coastguard Worker 
205*6777b538SAndroid Build Coastguard Worker   // Any DNS aliases for the remote endpoint. Includes all known aliases, e.g.
206*6777b538SAndroid Build Coastguard Worker   // from A, AAAA, or HTTPS, not just from the address used for the connection,
207*6777b538SAndroid Build Coastguard Worker   // in no particular order.
208*6777b538SAndroid Build Coastguard Worker   std::set<std::string> dns_aliases;
209*6777b538SAndroid Build Coastguard Worker 
210*6777b538SAndroid Build Coastguard Worker   // If not null, this indicates the response is stored during a certain browser
211*6777b538SAndroid Build Coastguard Worker   // session. Used for filtering cache access.
212*6777b538SAndroid Build Coastguard Worker   std::optional<int64_t> browser_run_id;
213*6777b538SAndroid Build Coastguard Worker 
214*6777b538SAndroid Build Coastguard Worker   // True if the response used a shared dictionary for decoding its body.
215*6777b538SAndroid Build Coastguard Worker   bool did_use_shared_dictionary = false;
216*6777b538SAndroid Build Coastguard Worker };
217*6777b538SAndroid Build Coastguard Worker 
218*6777b538SAndroid Build Coastguard Worker }  // namespace net
219*6777b538SAndroid Build Coastguard Worker 
220*6777b538SAndroid Build Coastguard Worker #endif  // NET_HTTP_HTTP_RESPONSE_INFO_H_
221