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