http_response_info.h revision 868fa2fe829687343ffae624259930155e16dbd8
1// Copyright (c) 2011 The Chromium Authors. All rights reserved.
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 <string>
9
10#include "base/time.h"
11#include "net/base/host_port_pair.h"
12#include "net/base/net_export.h"
13#include "net/http/http_vary_data.h"
14#include "net/ssl/ssl_info.h"
15
16class Pickle;
17
18namespace net {
19
20class AuthChallengeInfo;
21class HttpResponseHeaders;
22class IOBufferWithSize;
23class SSLCertRequestInfo;
24
25class NET_EXPORT HttpResponseInfo {
26 public:
27  // Describes the kind of connection used to fetch this response.
28  enum ConnectionInfo {
29    CONNECTION_INFO_UNKNOWN = 0,
30    CONNECTION_INFO_HTTP1 = 1,
31    CONNECTION_INFO_SPDY2 = 2,
32    CONNECTION_INFO_SPDY3 = 3,
33    CONNECTION_INFO_SPDY4 = 4,
34    CONNECTION_INFO_QUIC1_SPDY3 = 5,
35    NUM_OF_CONNECTION_INFOS,
36  };
37
38  HttpResponseInfo();
39  HttpResponseInfo(const HttpResponseInfo& rhs);
40  ~HttpResponseInfo();
41  HttpResponseInfo& operator=(const HttpResponseInfo& rhs);
42  // Even though we could get away with the copy ctor and default operator=,
43  // that would prevent us from doing a bunch of forward declaration.
44
45  // Initializes from the representation stored in the given pickle.
46  bool InitFromPickle(const Pickle& pickle, bool* response_truncated);
47
48  // Call this method to persist the response info.
49  void Persist(Pickle* pickle,
50               bool skip_transient_headers,
51               bool response_truncated) const;
52
53  // The following is only defined if the request_time member is set.
54  // If this response was resurrected from cache, then this bool is set, and
55  // request_time may corresponds to a time "far" in the past.  Note that
56  // stale content (perhaps un-cacheable) may be fetched from cache subject to
57  // the load flags specified on the request info.  For example, this is done
58  // when a user presses the back button to re-render pages, or at startup,
59  // when reloading previously visited pages (without going over the network).
60  bool was_cached;
61
62  // True if the request was fetched from cache rather than the network
63  // because of a LOAD_FROM_CACHE_IF_OFFLINE flag when the system
64  // was unable to contact the server.
65  bool server_data_unavailable;
66
67  // True if the request accessed the network in the process of retrieving
68  // data.
69  bool network_accessed;
70
71  // True if the request was fetched over a SPDY channel.
72  bool was_fetched_via_spdy;
73
74  // True if the npn was negotiated for this request.
75  bool was_npn_negotiated;
76
77  // True if the request was fetched via an explicit proxy.  The proxy could
78  // be any type of proxy, HTTP or SOCKS.  Note, we do not know if a
79  // transparent proxy may have been involved.
80  bool was_fetched_via_proxy;
81
82  // Whether the request use http proxy or server authentication.
83  bool did_use_http_auth;
84
85  // Remote address of the socket which fetched this resource.
86  //
87  // NOTE: If the response was served from the cache (was_cached is true),
88  // the socket address will be set to the address that the content came from
89  // originally.  This is true even if the response was re-validated using a
90  // different remote address, or if some of the content came from a byte-range
91  // request to a different address.
92  HostPortPair socket_address;
93
94  // Protocol negotiated with the server.
95  std::string npn_negotiated_protocol;
96
97  // The type of connection used for this response.
98  ConnectionInfo connection_info;
99
100  // The time at which the request was made that resulted in this response.
101  // For cached responses, this is the last time the cache entry was validated.
102  base::Time request_time;
103
104  // The time at which the response headers were received.  For cached
105  // this is the last time the cache entry was validated.
106  base::Time response_time;
107
108  // If the response headers indicate a 401 or 407 failure, then this structure
109  // will contain additional information about the authentication challenge.
110  scoped_refptr<AuthChallengeInfo> auth_challenge;
111
112  // The SSL client certificate request info.
113  // TODO(wtc): does this really belong in HttpResponseInfo?  I put it here
114  // because it is similar to |auth_challenge|, but unlike HTTP authentication
115  // challenge, client certificate request is not part of an HTTP response.
116  scoped_refptr<SSLCertRequestInfo> cert_request_info;
117
118  // The SSL connection info (if HTTPS).
119  SSLInfo ssl_info;
120
121  // The parsed response headers and status line.
122  scoped_refptr<HttpResponseHeaders> headers;
123
124  // The "Vary" header data for this response.
125  HttpVaryData vary_data;
126
127  // Any metadata asociated with this resource's cached data.
128  scoped_refptr<IOBufferWithSize> metadata;
129
130  static std::string ConnectionInfoToString(ConnectionInfo connection_info);
131};
132
133}  // namespace net
134
135#endif  // NET_HTTP_HTTP_RESPONSE_INFO_H_
136