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, 38868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CONNECTION_INFO_SPDY2 = 2, 39868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CONNECTION_INFO_SPDY3 = 3, 40558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch CONNECTION_INFO_SPDY4A2 = 4, 41868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) CONNECTION_INFO_QUIC1_SPDY3 = 5, 42558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch CONNECTION_INFO_HTTP2_DRAFT_04 = 6, 432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) NUM_OF_CONNECTION_INFOS, 442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) }; 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpResponseInfo(); 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpResponseInfo(const HttpResponseInfo& rhs); 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~HttpResponseInfo(); 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpResponseInfo& operator=(const HttpResponseInfo& rhs); 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Even though we could get away with the copy ctor and default operator=, 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that would prevent us from doing a bunch of forward declaration. 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initializes from the representation stored in the given pickle. 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool InitFromPickle(const Pickle& pickle, bool* response_truncated); 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Call this method to persist the response info. 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Persist(Pickle* pickle, 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool skip_transient_headers, 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool response_truncated) const; 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The following is only defined if the request_time member is set. 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If this response was resurrected from cache, then this bool is set, and 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request_time may corresponds to a time "far" in the past. Note that 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // stale content (perhaps un-cacheable) may be fetched from cache subject to 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the load flags specified on the request info. For example, this is done 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when a user presses the back button to re-render pages, or at startup, 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // when reloading previously visited pages (without going over the network). 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool was_cached; 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // True if the request was fetched from cache rather than the network 712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // because of a LOAD_FROM_CACHE_IF_OFFLINE flag when the system 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // was unable to contact the server. 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool server_data_unavailable; 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 75c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // True if the request accessed the network in the process of retrieving 76c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // data. 77c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool network_accessed; 78c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if the request was fetched over a SPDY channel. 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool was_fetched_via_spdy; 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if the npn was negotiated for this request. 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool was_npn_negotiated; 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // True if the request was fetched via an explicit proxy. The proxy could 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // be any type of proxy, HTTP or SOCKS. Note, we do not know if a 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // transparent proxy may have been involved. 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool was_fetched_via_proxy; 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 90c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Whether the request use http proxy or server authentication. 91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool did_use_http_auth; 92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Remote address of the socket which fetched this resource. 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NOTE: If the response was served from the cache (was_cached is true), 965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the socket address will be set to the address that the content came from 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // originally. This is true even if the response was re-validated using a 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // different remote address, or if some of the content came from a byte-range 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // request to a different address. 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HostPortPair socket_address; 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Protocol negotiated with the server. 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::string npn_negotiated_protocol; 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The type of connection used for this response. 1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ConnectionInfo connection_info; 1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The time at which the request was made that resulted in this response. 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // For cached responses, this is the last time the cache entry was validated. 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time request_time; 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The time at which the response headers were received. For cached 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this is the last time the cache entry was validated. 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) base::Time response_time; 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If the response headers indicate a 401 or 407 failure, then this structure 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // will contain additional information about the authentication challenge. 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<AuthChallengeInfo> auth_challenge; 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The SSL client certificate request info. 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // TODO(wtc): does this really belong in HttpResponseInfo? I put it here 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // because it is similar to |auth_challenge|, but unlike HTTP authentication 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // challenge, client certificate request is not part of an HTTP response. 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<SSLCertRequestInfo> cert_request_info; 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The SSL connection info (if HTTPS). 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) SSLInfo ssl_info; 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The parsed response headers and status line. 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<HttpResponseHeaders> headers; 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The "Vary" header data for this response. 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HttpVaryData vary_data; 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Any metadata asociated with this resource's cached data. 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<IOBufferWithSize> metadata; 137868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) 138558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch static ConnectionInfo ConnectionInfoFromNextProto(NextProto next_proto); 139558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 140868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) static std::string ConnectionInfoToString(ConnectionInfo connection_info); 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace net 1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // NET_HTTP_HTTP_RESPONSE_INFO_H_ 146