OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_response_info.h" | 5 #include "net/http/http_response_info.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/pickle.h" | 8 #include "base/pickle.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "net/base/auth.h" | 10 #include "net/base/auth.h" |
11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
13 #include "net/base/ssl_cert_request_info.h" | 13 #include "net/base/ssl_cert_request_info.h" |
14 #include "net/base/x509_certificate.h" | 14 #include "net/base/x509_certificate.h" |
15 #include "net/http/http_response_headers.h" | 15 #include "net/http/http_response_headers.h" |
16 | 16 |
17 using base::Time; | 17 using base::Time; |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 // These values can be bit-wise combined to form the flags field of the | 21 // These values can be bit-wise combined to form the flags field of the |
22 // serialized HttpResponseInfo. | 22 // serialized HttpResponseInfo. |
23 enum { | 23 enum { |
24 // The version of the response info used when persisting response info. | 24 // The version of the response info used when persisting response info. |
25 RESPONSE_INFO_VERSION = 1, | 25 RESPONSE_INFO_VERSION = 2, |
26 | |
27 // The minimum version supported for deserializing response info. | |
28 RESPONSE_INFO_MINIMUM_VERSION = 1, | |
26 | 29 |
27 // We reserve up to 8 bits for the version number. | 30 // We reserve up to 8 bits for the version number. |
28 RESPONSE_INFO_VERSION_MASK = 0xFF, | 31 RESPONSE_INFO_VERSION_MASK = 0xFF, |
29 | 32 |
30 // This bit is set if the response info has a cert at the end. | 33 // This bit is set if the response info has a cert at the end. |
31 RESPONSE_INFO_HAS_CERT = 1 << 8, | 34 RESPONSE_INFO_HAS_CERT = 1 << 8, |
32 | 35 |
33 // This bit is set if the response info has a security-bits field (security | 36 // This bit is set if the response info has a security-bits field (security |
34 // strength, in bits, of the SSL connection) at the end. | 37 // strength, in bits, of the SSL connection) at the end. |
35 RESPONSE_INFO_HAS_SECURITY_BITS = 1 << 9, | 38 RESPONSE_INFO_HAS_SECURITY_BITS = 1 << 9, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 | 104 |
102 bool HttpResponseInfo::InitFromPickle(const Pickle& pickle, | 105 bool HttpResponseInfo::InitFromPickle(const Pickle& pickle, |
103 bool* response_truncated) { | 106 bool* response_truncated) { |
104 void* iter = NULL; | 107 void* iter = NULL; |
105 | 108 |
106 // read flags and verify version | 109 // read flags and verify version |
107 int flags; | 110 int flags; |
108 if (!pickle.ReadInt(&iter, &flags)) | 111 if (!pickle.ReadInt(&iter, &flags)) |
109 return false; | 112 return false; |
110 int version = flags & RESPONSE_INFO_VERSION_MASK; | 113 int version = flags & RESPONSE_INFO_VERSION_MASK; |
111 if (version != RESPONSE_INFO_VERSION) { | 114 if (version < RESPONSE_INFO_MINIMUM_VERSION || |
115 version > RESPONSE_INFO_VERSION) { | |
112 DLOG(ERROR) << "unexpected response info version: " << version; | 116 DLOG(ERROR) << "unexpected response info version: " << version; |
113 return false; | 117 return false; |
114 } | 118 } |
115 | 119 |
116 // read request-time | 120 // read request-time |
117 int64 time_val; | 121 int64 time_val; |
118 if (!pickle.ReadInt64(&iter, &time_val)) | 122 if (!pickle.ReadInt64(&iter, &time_val)) |
119 return false; | 123 return false; |
120 request_time = Time::FromInternalValue(time_val); | 124 request_time = Time::FromInternalValue(time_val); |
121 was_cached = true; // Set status to show cache resurrection. | 125 was_cached = true; // Set status to show cache resurrection. |
122 | 126 |
123 // read response-time | 127 // read response-time |
124 if (!pickle.ReadInt64(&iter, &time_val)) | 128 if (!pickle.ReadInt64(&iter, &time_val)) |
125 return false; | 129 return false; |
126 response_time = Time::FromInternalValue(time_val); | 130 response_time = Time::FromInternalValue(time_val); |
127 | 131 |
128 // read response-headers | 132 // read response-headers |
129 headers = new HttpResponseHeaders(pickle, &iter); | 133 headers = new HttpResponseHeaders(pickle, &iter); |
130 DCHECK_NE(headers->response_code(), -1); | 134 DCHECK_NE(headers->response_code(), -1); |
131 | 135 |
132 // read ssl-info | 136 // read ssl-info |
133 if (flags & RESPONSE_INFO_HAS_CERT) { | 137 if (flags & RESPONSE_INFO_HAS_CERT) { |
134 ssl_info.cert = | 138 // Version 1 only serialized only the end-entity certificate, |
rvargas (doing something else)
2011/04/20 23:51:14
nit: extra only
| |
135 X509Certificate::CreateFromPickle(pickle, &iter); | 139 // while subsequent versions include the entire chain. |
wtc
2011/04/20 23:07:58
This comment should be moved (or copied) to the de
| |
140 X509Certificate::PickleType type = (version == 1) ? | |
141 X509Certificate::PICKLETYPE_SINGLE_CERTIFICATE : | |
142 X509Certificate::PICKLETYPE_CERTIFICATE_CHAIN; | |
143 ssl_info.cert = X509Certificate::CreateFromPickle(pickle, &iter, type); | |
136 } | 144 } |
137 if (flags & RESPONSE_INFO_HAS_CERT_STATUS) { | 145 if (flags & RESPONSE_INFO_HAS_CERT_STATUS) { |
138 int cert_status; | 146 int cert_status; |
139 if (!pickle.ReadInt(&iter, &cert_status)) | 147 if (!pickle.ReadInt(&iter, &cert_status)) |
140 return false; | 148 return false; |
141 ssl_info.cert_status = cert_status; | 149 ssl_info.cert_status = cert_status; |
142 } | 150 } |
143 if (flags & RESPONSE_INFO_HAS_SECURITY_BITS) { | 151 if (flags & RESPONSE_INFO_HAS_SECURITY_BITS) { |
144 int security_bits; | 152 int security_bits; |
145 if (!pickle.ReadInt(&iter, &security_bits)) | 153 if (!pickle.ReadInt(&iter, &security_bits)) |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 } | 232 } |
225 | 233 |
226 if (vary_data.is_valid()) | 234 if (vary_data.is_valid()) |
227 vary_data.Persist(pickle); | 235 vary_data.Persist(pickle); |
228 | 236 |
229 pickle->WriteString(socket_address.host()); | 237 pickle->WriteString(socket_address.host()); |
230 pickle->WriteUInt16(socket_address.port()); | 238 pickle->WriteUInt16(socket_address.port()); |
231 } | 239 } |
232 | 240 |
233 } // namespace net | 241 } // namespace net |
OLD | NEW |