15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2011 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_HTTP_HTTP_RESPONSE_INFO_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_HTTP_HTTP_RESPONSE_INFO_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/host_port_pair.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/net_export.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/http/http_vary_data.h" 14558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch#include "net/socket/next_proto.h" 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "net/ssl/ssl_info.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Pickle; 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net { 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class AuthChallengeInfo; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HttpResponseHeaders; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class IOBufferWithSize; 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SSLCertRequestInfo; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT HttpResponseInfo { 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Describes the kind of connection used to fetch this response. 29558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // 30558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // NOTE: This is persisted to the cache, so make sure not to reorder 31558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // these values. 32558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // 33558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // TODO(akalin): Better yet, just use a string instead of an enum, 34558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch // like |npn_negotiated_protocol|. 352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) enum ConnectionInfo { 36868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CONNECTION_INFO_UNKNOWN = 0, 37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CONNECTION_INFO_HTTP1 = 1, 384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) CONNECTION_INFO_DEPRECATED_SPDY2 = 2, 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CONNECTION_INFO_SPDY3 = 3, 40a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch CONNECTION_INFO_SPDY4 = 4, 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CONNECTION_INFO_QUIC1_SPDY3 = 5, 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NUM_OF_CONNECTION_INFOS, 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpResponseInfo(); 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpResponseInfo(const HttpResponseInfo& rhs); 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~HttpResponseInfo(); 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpResponseInfo& operator=(const HttpResponseInfo& rhs); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Even though we could get away with the copy ctor and default operator=, 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that would prevent us from doing a bunch of forward declaration. 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initializes from the representation stored in the given pickle. 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool InitFromPickle(const Pickle& pickle, bool* response_truncated); 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Call this method to persist the response info. 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Persist(Pickle* pickle, 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool skip_transient_headers, 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool response_truncated) const; 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The following is only defined if the request_time member is set. 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // If this resource was found in the cache, then this bool is set, and 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request_time may corresponds to a time "far" in the past. Note that 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // stale content (perhaps un-cacheable) may be fetched from cache subject to 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the load flags specified on the request info. For example, this is done 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when a user presses the back button to re-render pages, or at startup, 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when reloading previously visited pages (without going over the network). 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Note also that under normal circumstances, was_cached is set to the correct 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // value even if the request fails. 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool was_cached; 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // True if the request was fetched from cache rather than the network 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // because of a LOAD_FROM_CACHE_IF_OFFLINE flag when the system 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // was unable to contact the server. 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool server_data_unavailable; 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // True if the request accessed the network in the process of retrieving 77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // data. 78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool network_accessed; 79c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if the request was fetched over a SPDY channel. 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool was_fetched_via_spdy; 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if the npn was negotiated for this request. 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool was_npn_negotiated; 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if the request was fetched via an explicit proxy. The proxy could 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be any type of proxy, HTTP or SOCKS. Note, we do not know if a 88f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // transparent proxy may have been involved. If true, |proxy_server| contains 89f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // the name of the proxy server that was used. 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool was_fetched_via_proxy; 91f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) HostPortPair proxy_server; 925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 93c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Whether the request use http proxy or server authentication. 94c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool did_use_http_auth; 95c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Remote address of the socket which fetched this resource. 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NOTE: If the response was served from the cache (was_cached is true), 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the socket address will be set to the address that the content came from 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // originally. This is true even if the response was re-validated using a 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // different remote address, or if some of the content came from a byte-range 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request to a different address. 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HostPortPair socket_address; 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Protocol negotiated with the server. 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string npn_negotiated_protocol; 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The type of connection used for this response. 1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ConnectionInfo connection_info; 1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The time at which the request was made that resulted in this response. 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For cached responses, this is the last time the cache entry was validated. 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time request_time; 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The time at which the response headers were received. For cached 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this is the last time the cache entry was validated. 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time response_time; 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the response headers indicate a 401 or 407 failure, then this structure 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will contain additional information about the authentication challenge. 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<AuthChallengeInfo> auth_challenge; 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The SSL client certificate request info. 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(wtc): does this really belong in HttpResponseInfo? I put it here 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // because it is similar to |auth_challenge|, but unlike HTTP authentication 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // challenge, client certificate request is not part of an HTTP response. 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<SSLCertRequestInfo> cert_request_info; 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The SSL connection info (if HTTPS). 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SSLInfo ssl_info; 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The parsed response headers and status line. 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<HttpResponseHeaders> headers; 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The "Vary" header data for this response. 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpVaryData vary_data; 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Any metadata asociated with this resource's cached data. 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<IOBufferWithSize> metadata; 140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 141558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch static ConnectionInfo ConnectionInfoFromNextProto(NextProto next_proto); 142558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 143868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) static std::string ConnectionInfoToString(ConnectionInfo connection_info); 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace net 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // NET_HTTP_HTTP_RESPONSE_INFO_H_ 149