| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 | 45 |
| 46 // This bit is set if the response was received via SPDY. | 46 // This bit is set if the response was received via SPDY. |
| 47 RESPONSE_INFO_WAS_SPDY = 1 << 13, | 47 RESPONSE_INFO_WAS_SPDY = 1 << 13, |
| 48 | 48 |
| 49 // This bit is set if the request has NPN negotiated. | 49 // This bit is set if the request has NPN negotiated. |
| 50 RESPONSE_INFO_WAS_NPN = 1 << 14, | 50 RESPONSE_INFO_WAS_NPN = 1 << 14, |
| 51 | 51 |
| 52 // This bit is set if the request was fetched via an explicit proxy. | 52 // This bit is set if the request was fetched via an explicit proxy. |
| 53 RESPONSE_INFO_WAS_PROXY = 1 << 15, | 53 RESPONSE_INFO_WAS_PROXY = 1 << 15, |
| 54 | 54 |
| 55 // This bit is set if response could use alternate protocol. However, browser | |
| 56 // will ingore the alternate protocol if spdy is not enabled. | |
| 57 RESPONSE_INFO_WAS_ALTERNATE_PROTOCOL_AVAILABLE = 1 << 16, | |
| 58 | |
| 59 // TODO(darin): Add other bits to indicate alternate request methods. | 55 // TODO(darin): Add other bits to indicate alternate request methods. |
| 60 // For now, we don't support storing those. | 56 // For now, we don't support storing those. |
| 61 }; | 57 }; |
| 62 | 58 |
| 63 HttpResponseInfo::HttpResponseInfo() | 59 HttpResponseInfo::HttpResponseInfo() |
| 64 : was_cached(false), | 60 : was_cached(false), |
| 65 was_fetched_via_spdy(false), | 61 was_fetched_via_spdy(false), |
| 66 was_npn_negotiated(false), | 62 was_npn_negotiated(false), |
| 67 was_alternate_protocol_available(false), | |
| 68 was_fetched_via_proxy(false) { | 63 was_fetched_via_proxy(false) { |
| 69 } | 64 } |
| 70 | 65 |
| 71 HttpResponseInfo::HttpResponseInfo(const HttpResponseInfo& rhs) | 66 HttpResponseInfo::HttpResponseInfo(const HttpResponseInfo& rhs) |
| 72 : was_cached(rhs.was_cached), | 67 : was_cached(rhs.was_cached), |
| 73 was_fetched_via_spdy(rhs.was_fetched_via_spdy), | 68 was_fetched_via_spdy(rhs.was_fetched_via_spdy), |
| 74 was_npn_negotiated(rhs.was_npn_negotiated), | 69 was_npn_negotiated(rhs.was_npn_negotiated), |
| 75 was_alternate_protocol_available(rhs.was_alternate_protocol_available), | |
| 76 was_fetched_via_proxy(rhs.was_fetched_via_proxy), | 70 was_fetched_via_proxy(rhs.was_fetched_via_proxy), |
| 77 socket_address(rhs.socket_address), | 71 socket_address(rhs.socket_address), |
| 78 request_time(rhs.request_time), | 72 request_time(rhs.request_time), |
| 79 response_time(rhs.response_time), | 73 response_time(rhs.response_time), |
| 80 auth_challenge(rhs.auth_challenge), | 74 auth_challenge(rhs.auth_challenge), |
| 81 cert_request_info(rhs.cert_request_info), | 75 cert_request_info(rhs.cert_request_info), |
| 82 ssl_info(rhs.ssl_info), | 76 ssl_info(rhs.ssl_info), |
| 83 headers(rhs.headers), | 77 headers(rhs.headers), |
| 84 vary_data(rhs.vary_data), | 78 vary_data(rhs.vary_data), |
| 85 metadata(rhs.metadata) { | 79 metadata(rhs.metadata) { |
| 86 } | 80 } |
| 87 | 81 |
| 88 HttpResponseInfo::~HttpResponseInfo() { | 82 HttpResponseInfo::~HttpResponseInfo() { |
| 89 } | 83 } |
| 90 | 84 |
| 91 HttpResponseInfo& HttpResponseInfo::operator=(const HttpResponseInfo& rhs) { | 85 HttpResponseInfo& HttpResponseInfo::operator=(const HttpResponseInfo& rhs) { |
| 92 was_cached = rhs.was_cached; | 86 was_cached = rhs.was_cached; |
| 93 was_fetched_via_spdy = rhs.was_fetched_via_spdy; | 87 was_fetched_via_spdy = rhs.was_fetched_via_spdy; |
| 94 was_npn_negotiated = rhs.was_npn_negotiated; | 88 was_npn_negotiated = rhs.was_npn_negotiated; |
| 95 was_alternate_protocol_available = rhs.was_alternate_protocol_available; | |
| 96 was_fetched_via_proxy = rhs.was_fetched_via_proxy; | 89 was_fetched_via_proxy = rhs.was_fetched_via_proxy; |
| 97 socket_address = rhs.socket_address; | 90 socket_address = rhs.socket_address; |
| 98 request_time = rhs.request_time; | 91 request_time = rhs.request_time; |
| 99 response_time = rhs.response_time; | 92 response_time = rhs.response_time; |
| 100 auth_challenge = rhs.auth_challenge; | 93 auth_challenge = rhs.auth_challenge; |
| 101 cert_request_info = rhs.cert_request_info; | 94 cert_request_info = rhs.cert_request_info; |
| 102 ssl_info = rhs.ssl_info; | 95 ssl_info = rhs.ssl_info; |
| 103 headers = rhs.headers; | 96 headers = rhs.headers; |
| 104 vary_data = rhs.vary_data; | 97 vary_data = rhs.vary_data; |
| 105 metadata = rhs.metadata; | 98 metadata = rhs.metadata; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 uint16 socket_address_port; | 162 uint16 socket_address_port; |
| 170 if (!pickle.ReadUInt16(&iter, &socket_address_port)) | 163 if (!pickle.ReadUInt16(&iter, &socket_address_port)) |
| 171 return false; | 164 return false; |
| 172 socket_address = HostPortPair(socket_address_host, socket_address_port); | 165 socket_address = HostPortPair(socket_address_host, socket_address_port); |
| 173 } | 166 } |
| 174 | 167 |
| 175 was_fetched_via_spdy = (flags & RESPONSE_INFO_WAS_SPDY) != 0; | 168 was_fetched_via_spdy = (flags & RESPONSE_INFO_WAS_SPDY) != 0; |
| 176 | 169 |
| 177 was_npn_negotiated = (flags & RESPONSE_INFO_WAS_NPN) != 0; | 170 was_npn_negotiated = (flags & RESPONSE_INFO_WAS_NPN) != 0; |
| 178 | 171 |
| 179 was_alternate_protocol_available = | |
| 180 (flags & RESPONSE_INFO_WAS_ALTERNATE_PROTOCOL_AVAILABLE) != 0; | |
| 181 | |
| 182 was_fetched_via_proxy = (flags & RESPONSE_INFO_WAS_PROXY) != 0; | 172 was_fetched_via_proxy = (flags & RESPONSE_INFO_WAS_PROXY) != 0; |
| 183 | 173 |
| 184 *response_truncated = (flags & RESPONSE_INFO_TRUNCATED) ? true : false; | 174 *response_truncated = (flags & RESPONSE_INFO_TRUNCATED) ? true : false; |
| 185 | 175 |
| 186 return true; | 176 return true; |
| 187 } | 177 } |
| 188 | 178 |
| 189 void HttpResponseInfo::Persist(Pickle* pickle, | 179 void HttpResponseInfo::Persist(Pickle* pickle, |
| 190 bool skip_transient_headers, | 180 bool skip_transient_headers, |
| 191 bool response_truncated) const { | 181 bool response_truncated) const { |
| 192 int flags = RESPONSE_INFO_VERSION; | 182 int flags = RESPONSE_INFO_VERSION; |
| 193 if (ssl_info.is_valid()) { | 183 if (ssl_info.is_valid()) { |
| 194 flags |= RESPONSE_INFO_HAS_CERT; | 184 flags |= RESPONSE_INFO_HAS_CERT; |
| 195 flags |= RESPONSE_INFO_HAS_CERT_STATUS; | 185 flags |= RESPONSE_INFO_HAS_CERT_STATUS; |
| 196 if (ssl_info.security_bits != -1) | 186 if (ssl_info.security_bits != -1) |
| 197 flags |= RESPONSE_INFO_HAS_SECURITY_BITS; | 187 flags |= RESPONSE_INFO_HAS_SECURITY_BITS; |
| 198 // TODO(wtc): we should persist ssl_info.connection_status. | 188 // TODO(wtc): we should persist ssl_info.connection_status. |
| 199 } | 189 } |
| 200 if (vary_data.is_valid()) | 190 if (vary_data.is_valid()) |
| 201 flags |= RESPONSE_INFO_HAS_VARY_DATA; | 191 flags |= RESPONSE_INFO_HAS_VARY_DATA; |
| 202 if (response_truncated) | 192 if (response_truncated) |
| 203 flags |= RESPONSE_INFO_TRUNCATED; | 193 flags |= RESPONSE_INFO_TRUNCATED; |
| 204 if (was_fetched_via_spdy) | 194 if (was_fetched_via_spdy) |
| 205 flags |= RESPONSE_INFO_WAS_SPDY; | 195 flags |= RESPONSE_INFO_WAS_SPDY; |
| 206 if (was_npn_negotiated) | 196 if (was_npn_negotiated) |
| 207 flags |= RESPONSE_INFO_WAS_NPN; | 197 flags |= RESPONSE_INFO_WAS_NPN; |
| 208 if (was_alternate_protocol_available) | |
| 209 flags |= RESPONSE_INFO_WAS_ALTERNATE_PROTOCOL_AVAILABLE; | |
| 210 if (was_fetched_via_proxy) | 198 if (was_fetched_via_proxy) |
| 211 flags |= RESPONSE_INFO_WAS_PROXY; | 199 flags |= RESPONSE_INFO_WAS_PROXY; |
| 212 | 200 |
| 213 pickle->WriteInt(flags); | 201 pickle->WriteInt(flags); |
| 214 pickle->WriteInt64(request_time.ToInternalValue()); | 202 pickle->WriteInt64(request_time.ToInternalValue()); |
| 215 pickle->WriteInt64(response_time.ToInternalValue()); | 203 pickle->WriteInt64(response_time.ToInternalValue()); |
| 216 | 204 |
| 217 net::HttpResponseHeaders::PersistOptions persist_options = | 205 net::HttpResponseHeaders::PersistOptions persist_options = |
| 218 net::HttpResponseHeaders::PERSIST_RAW; | 206 net::HttpResponseHeaders::PERSIST_RAW; |
| 219 | 207 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 236 } | 224 } |
| 237 | 225 |
| 238 if (vary_data.is_valid()) | 226 if (vary_data.is_valid()) |
| 239 vary_data.Persist(pickle); | 227 vary_data.Persist(pickle); |
| 240 | 228 |
| 241 pickle->WriteString(socket_address.host()); | 229 pickle->WriteString(socket_address.host()); |
| 242 pickle->WriteUInt16(socket_address.port()); | 230 pickle->WriteUInt16(socket_address.port()); |
| 243 } | 231 } |
| 244 | 232 |
| 245 } // namespace net | 233 } // namespace net |
| OLD | NEW |