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 bool WasFetchedViaProxy() const; 108 109 // Information about the proxy chain used to fetch this response, if any. 110 ProxyChain proxy_chain; 111 112 // Whether this request was eligible for IP Protection based on the request 113 // being a match to the masked domain list, if available. 114 // This field is not persisted by `Persist()` and not restored by 115 // `InitFromPickle()`. 116 bool was_mdl_match = false; 117 118 // Whether the request use http proxy or server authentication. 119 bool did_use_http_auth = false; 120 121 // True if the resource was originally fetched for a prefetch and has not been 122 // used since. 123 bool unused_since_prefetch = false; 124 125 // True if the response is a prefetch whose reuse is "restricted". This means 126 // it can only be reused from the cache by requests that are marked as able to 127 // use restricted prefetches. 128 bool restricted_prefetch = false; 129 130 // True if this resource is stale and needs async revalidation. 131 // This value is not persisted by Persist(); it is only ever set when the 132 // response is retrieved from the cache. 133 bool async_revalidation_requested = false; 134 135 // stale-while-revalidate, if any, will be honored until time given by 136 // |stale_revalidate_timeout|. This value is latched the first time 137 // stale-while-revalidate is used until the resource is revalidated. 138 base::Time stale_revalidate_timeout; 139 140 // Remote address of the socket which fetched this resource. 141 // 142 // NOTE: If the response was served from the cache (was_cached is true), 143 // the socket address will be set to the address that the content came from 144 // originally. This is true even if the response was re-validated using a 145 // different remote address, or if some of the content came from a byte-range 146 // request to a different address. 147 IPEndPoint remote_endpoint; 148 149 // Protocol negotiated with the server. 150 std::string alpn_negotiated_protocol; 151 152 // The reason why Chrome uses a specific transport protocol for HTTP 153 // semantics. 154 AlternateProtocolUsage alternate_protocol_usage = 155 AlternateProtocolUsage::ALTERNATE_PROTOCOL_USAGE_UNSPECIFIED_REASON; 156 157 // The type of connection used for this response. 158 HttpConnectionInfo connection_info = HttpConnectionInfo::kUNKNOWN; 159 160 // The time at which the request was made that resulted in this response. 161 // For cached responses, this is the last time the cache entry was validated. 162 base::Time request_time; 163 164 // The time at which the response headers were received. For cached 165 // this is the last time the cache entry was validated. 166 base::Time response_time; 167 168 // Like response_time, but ignoring revalidations. 169 base::Time original_response_time; 170 171 // Host resolution error info. 172 ResolveErrorInfo resolve_error_info; 173 174 // If the response headers indicate a 401 or 407 failure, then this structure 175 // will contain additional information about the authentication challenge. 176 std::optional<AuthChallengeInfo> auth_challenge; 177 178 // The SSL client certificate request info. 179 // TODO(wtc): does this really belong in HttpResponseInfo? I put it here 180 // because it is similar to |auth_challenge|, but unlike HTTP authentication 181 // challenge, client certificate request is not part of an HTTP response. 182 scoped_refptr<SSLCertRequestInfo> cert_request_info; 183 184 // The SSL connection info (if HTTPS). Note that when a response is 185 // served from cache, not every field is present. See 186 // HttpResponseInfo::InitFromPickle(). 187 SSLInfo ssl_info; 188 189 // The parsed response headers and status line. 190 scoped_refptr<HttpResponseHeaders> headers; 191 192 // The "Vary" header data for this response. 193 // Initialized and used by HttpCache::Transaction. May also be passed to an 194 // auxiliary in-memory cache in the network service. 195 HttpVaryData vary_data; 196 197 // Any DNS aliases for the remote endpoint. Includes all known aliases, e.g. 198 // from A, AAAA, or HTTPS, not just from the address used for the connection, 199 // in no particular order. 200 std::set<std::string> dns_aliases; 201 202 // If not null, this indicates the response is stored during a certain browser 203 // session. Used for filtering cache access. 204 std::optional<int64_t> browser_run_id; 205 206 // True if the response used a shared dictionary for decoding its body. 207 bool did_use_shared_dictionary = false; 208 }; 209 210 } // namespace net 211 212 #endif // NET_HTTP_HTTP_RESPONSE_INFO_H_ 213