| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/time.h" | 9 #include "base/time/time.h" |
| 10 #include "net/base/auth.h" | 10 #include "net/base/auth.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 | 62 |
| 63 // This bit is set if the response info has vary header data. | 63 // This bit is set if the response info has vary header data. |
| 64 RESPONSE_INFO_HAS_VARY_DATA = 1 << 11, | 64 RESPONSE_INFO_HAS_VARY_DATA = 1 << 11, |
| 65 | 65 |
| 66 // This bit is set if the request was cancelled before completion. | 66 // This bit is set if the request was cancelled before completion. |
| 67 RESPONSE_INFO_TRUNCATED = 1 << 12, | 67 RESPONSE_INFO_TRUNCATED = 1 << 12, |
| 68 | 68 |
| 69 // This bit is set if the response was received via SPDY. | 69 // This bit is set if the response was received via SPDY. |
| 70 RESPONSE_INFO_WAS_SPDY = 1 << 13, | 70 RESPONSE_INFO_WAS_SPDY = 1 << 13, |
| 71 | 71 |
| 72 // This bit is set if the request has NPN negotiated. | 72 // This bit is set if the request has ALPN negotiated. |
| 73 RESPONSE_INFO_WAS_NPN = 1 << 14, | 73 RESPONSE_INFO_WAS_ALPN = 1 << 14, |
| 74 | 74 |
| 75 // This bit is set if the request was fetched via an explicit proxy. | 75 // This bit is set if the request was fetched via an explicit proxy. |
| 76 RESPONSE_INFO_WAS_PROXY = 1 << 15, | 76 RESPONSE_INFO_WAS_PROXY = 1 << 15, |
| 77 | 77 |
| 78 // This bit is set if the response info has an SSL connection status field. | 78 // This bit is set if the response info has an SSL connection status field. |
| 79 // This contains the ciphersuite used to fetch the resource as well as the | 79 // This contains the ciphersuite used to fetch the resource as well as the |
| 80 // protocol version, compression method and whether SSLv3 fallback was used. | 80 // protocol version, compression method and whether SSLv3 fallback was used. |
| 81 RESPONSE_INFO_HAS_SSL_CONNECTION_STATUS = 1 << 16, | 81 RESPONSE_INFO_HAS_SSL_CONNECTION_STATUS = 1 << 16, |
| 82 | 82 |
| 83 // This bit is set if the response info has protocol version. | 83 // This bit is set if the response info has protocol version. |
| 84 RESPONSE_INFO_HAS_NPN_NEGOTIATED_PROTOCOL = 1 << 17, | 84 RESPONSE_INFO_HAS_ALPN_NEGOTIATED_PROTOCOL = 1 << 17, |
| 85 | 85 |
| 86 // This bit is set if the response info has connection info. | 86 // This bit is set if the response info has connection info. |
| 87 RESPONSE_INFO_HAS_CONNECTION_INFO = 1 << 18, | 87 RESPONSE_INFO_HAS_CONNECTION_INFO = 1 << 18, |
| 88 | 88 |
| 89 // This bit is set if the request has http authentication. | 89 // This bit is set if the request has http authentication. |
| 90 RESPONSE_INFO_USE_HTTP_AUTHENTICATION = 1 << 19, | 90 RESPONSE_INFO_USE_HTTP_AUTHENTICATION = 1 << 19, |
| 91 | 91 |
| 92 // This bit is set if ssl_info has SCTs. | 92 // This bit is set if ssl_info has SCTs. |
| 93 RESPONSE_INFO_HAS_SIGNED_CERTIFICATE_TIMESTAMPS = 1 << 20, | 93 RESPONSE_INFO_HAS_SIGNED_CERTIFICATE_TIMESTAMPS = 1 << 20, |
| 94 | 94 |
| 95 RESPONSE_INFO_UNUSED_SINCE_PREFETCH = 1 << 21, | 95 RESPONSE_INFO_UNUSED_SINCE_PREFETCH = 1 << 21, |
| 96 | 96 |
| 97 // This bit is set if the response has a key-exchange-info field at the end. | 97 // This bit is set if the response has a key-exchange-info field at the end. |
| 98 RESPONSE_INFO_HAS_KEY_EXCHANGE_INFO = 1 << 22, | 98 RESPONSE_INFO_HAS_KEY_EXCHANGE_INFO = 1 << 22, |
| 99 | 99 |
| 100 // This bit is set if ssl_info recorded that PKP was bypassed due to a local | 100 // This bit is set if ssl_info recorded that PKP was bypassed due to a local |
| 101 // trust anchor. | 101 // trust anchor. |
| 102 RESPONSE_INFO_PKP_BYPASSED = 1 << 23, | 102 RESPONSE_INFO_PKP_BYPASSED = 1 << 23, |
| 103 | 103 |
| 104 // TODO(darin): Add other bits to indicate alternate request methods. | 104 // TODO(darin): Add other bits to indicate alternate request methods. |
| 105 // For now, we don't support storing those. | 105 // For now, we don't support storing those. |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 HttpResponseInfo::HttpResponseInfo() | 108 HttpResponseInfo::HttpResponseInfo() |
| 109 : was_cached(false), | 109 : was_cached(false), |
| 110 cache_entry_status(CacheEntryStatus::ENTRY_UNDEFINED), | 110 cache_entry_status(CacheEntryStatus::ENTRY_UNDEFINED), |
| 111 server_data_unavailable(false), | 111 server_data_unavailable(false), |
| 112 network_accessed(false), | 112 network_accessed(false), |
| 113 was_fetched_via_spdy(false), | 113 was_fetched_via_spdy(false), |
| 114 was_npn_negotiated(false), | 114 was_alpn_negotiated(false), |
| 115 was_fetched_via_proxy(false), | 115 was_fetched_via_proxy(false), |
| 116 did_use_http_auth(false), | 116 did_use_http_auth(false), |
| 117 unused_since_prefetch(false), | 117 unused_since_prefetch(false), |
| 118 async_revalidation_required(false), | 118 async_revalidation_required(false), |
| 119 connection_info(CONNECTION_INFO_UNKNOWN) {} | 119 connection_info(CONNECTION_INFO_UNKNOWN) {} |
| 120 | 120 |
| 121 HttpResponseInfo::HttpResponseInfo(const HttpResponseInfo& rhs) | 121 HttpResponseInfo::HttpResponseInfo(const HttpResponseInfo& rhs) |
| 122 : was_cached(rhs.was_cached), | 122 : was_cached(rhs.was_cached), |
| 123 cache_entry_status(rhs.cache_entry_status), | 123 cache_entry_status(rhs.cache_entry_status), |
| 124 server_data_unavailable(rhs.server_data_unavailable), | 124 server_data_unavailable(rhs.server_data_unavailable), |
| 125 network_accessed(rhs.network_accessed), | 125 network_accessed(rhs.network_accessed), |
| 126 was_fetched_via_spdy(rhs.was_fetched_via_spdy), | 126 was_fetched_via_spdy(rhs.was_fetched_via_spdy), |
| 127 was_npn_negotiated(rhs.was_npn_negotiated), | 127 was_alpn_negotiated(rhs.was_alpn_negotiated), |
| 128 was_fetched_via_proxy(rhs.was_fetched_via_proxy), | 128 was_fetched_via_proxy(rhs.was_fetched_via_proxy), |
| 129 proxy_server(rhs.proxy_server), | 129 proxy_server(rhs.proxy_server), |
| 130 did_use_http_auth(rhs.did_use_http_auth), | 130 did_use_http_auth(rhs.did_use_http_auth), |
| 131 unused_since_prefetch(rhs.unused_since_prefetch), | 131 unused_since_prefetch(rhs.unused_since_prefetch), |
| 132 async_revalidation_required(rhs.async_revalidation_required), | 132 async_revalidation_required(rhs.async_revalidation_required), |
| 133 socket_address(rhs.socket_address), | 133 socket_address(rhs.socket_address), |
| 134 npn_negotiated_protocol(rhs.npn_negotiated_protocol), | 134 alpn_negotiated_protocol(rhs.alpn_negotiated_protocol), |
| 135 connection_info(rhs.connection_info), | 135 connection_info(rhs.connection_info), |
| 136 request_time(rhs.request_time), | 136 request_time(rhs.request_time), |
| 137 response_time(rhs.response_time), | 137 response_time(rhs.response_time), |
| 138 auth_challenge(rhs.auth_challenge), | 138 auth_challenge(rhs.auth_challenge), |
| 139 cert_request_info(rhs.cert_request_info), | 139 cert_request_info(rhs.cert_request_info), |
| 140 ssl_info(rhs.ssl_info), | 140 ssl_info(rhs.ssl_info), |
| 141 headers(rhs.headers), | 141 headers(rhs.headers), |
| 142 vary_data(rhs.vary_data), | 142 vary_data(rhs.vary_data), |
| 143 metadata(rhs.metadata) {} | 143 metadata(rhs.metadata) {} |
| 144 | 144 |
| 145 HttpResponseInfo::~HttpResponseInfo() { | 145 HttpResponseInfo::~HttpResponseInfo() { |
| 146 } | 146 } |
| 147 | 147 |
| 148 HttpResponseInfo& HttpResponseInfo::operator=(const HttpResponseInfo& rhs) { | 148 HttpResponseInfo& HttpResponseInfo::operator=(const HttpResponseInfo& rhs) { |
| 149 was_cached = rhs.was_cached; | 149 was_cached = rhs.was_cached; |
| 150 cache_entry_status = rhs.cache_entry_status; | 150 cache_entry_status = rhs.cache_entry_status; |
| 151 server_data_unavailable = rhs.server_data_unavailable; | 151 server_data_unavailable = rhs.server_data_unavailable; |
| 152 network_accessed = rhs.network_accessed; | 152 network_accessed = rhs.network_accessed; |
| 153 was_fetched_via_spdy = rhs.was_fetched_via_spdy; | 153 was_fetched_via_spdy = rhs.was_fetched_via_spdy; |
| 154 proxy_server = rhs.proxy_server; | 154 proxy_server = rhs.proxy_server; |
| 155 was_npn_negotiated = rhs.was_npn_negotiated; | 155 was_alpn_negotiated = rhs.was_alpn_negotiated; |
| 156 was_fetched_via_proxy = rhs.was_fetched_via_proxy; | 156 was_fetched_via_proxy = rhs.was_fetched_via_proxy; |
| 157 did_use_http_auth = rhs.did_use_http_auth; | 157 did_use_http_auth = rhs.did_use_http_auth; |
| 158 unused_since_prefetch = rhs.unused_since_prefetch; | 158 unused_since_prefetch = rhs.unused_since_prefetch; |
| 159 async_revalidation_required = rhs.async_revalidation_required; | 159 async_revalidation_required = rhs.async_revalidation_required; |
| 160 socket_address = rhs.socket_address; | 160 socket_address = rhs.socket_address; |
| 161 npn_negotiated_protocol = rhs.npn_negotiated_protocol; | 161 alpn_negotiated_protocol = rhs.alpn_negotiated_protocol; |
| 162 connection_info = rhs.connection_info; | 162 connection_info = rhs.connection_info; |
| 163 request_time = rhs.request_time; | 163 request_time = rhs.request_time; |
| 164 response_time = rhs.response_time; | 164 response_time = rhs.response_time; |
| 165 auth_challenge = rhs.auth_challenge; | 165 auth_challenge = rhs.auth_challenge; |
| 166 cert_request_info = rhs.cert_request_info; | 166 cert_request_info = rhs.cert_request_info; |
| 167 ssl_info = rhs.ssl_info; | 167 ssl_info = rhs.ssl_info; |
| 168 headers = rhs.headers; | 168 headers = rhs.headers; |
| 169 vary_data = rhs.vary_data; | 169 vary_data = rhs.vary_data; |
| 170 metadata = rhs.metadata; | 170 metadata = rhs.metadata; |
| 171 return *this; | 171 return *this; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 if (!iter.ReadUInt16(&socket_address_port)) | 262 if (!iter.ReadUInt16(&socket_address_port)) |
| 263 return false; | 263 return false; |
| 264 socket_address = HostPortPair(socket_address_host, socket_address_port); | 264 socket_address = HostPortPair(socket_address_host, socket_address_port); |
| 265 } else if (version > 1) { | 265 } else if (version > 1) { |
| 266 // socket_address was not always present in version 1 of the response | 266 // socket_address was not always present in version 1 of the response |
| 267 // info, so we don't fail if it can't be read. | 267 // info, so we don't fail if it can't be read. |
| 268 return false; | 268 return false; |
| 269 } | 269 } |
| 270 | 270 |
| 271 // Read protocol-version. | 271 // Read protocol-version. |
| 272 if (flags & RESPONSE_INFO_HAS_NPN_NEGOTIATED_PROTOCOL) { | 272 if (flags & RESPONSE_INFO_HAS_ALPN_NEGOTIATED_PROTOCOL) { |
| 273 if (!iter.ReadString(&npn_negotiated_protocol)) | 273 if (!iter.ReadString(&alpn_negotiated_protocol)) |
| 274 return false; | 274 return false; |
| 275 } | 275 } |
| 276 | 276 |
| 277 // Read connection info. | 277 // Read connection info. |
| 278 if (flags & RESPONSE_INFO_HAS_CONNECTION_INFO) { | 278 if (flags & RESPONSE_INFO_HAS_CONNECTION_INFO) { |
| 279 int value; | 279 int value; |
| 280 if (!iter.ReadInt(&value)) | 280 if (!iter.ReadInt(&value)) |
| 281 return false; | 281 return false; |
| 282 | 282 |
| 283 if (value > static_cast<int>(CONNECTION_INFO_UNKNOWN) && | 283 if (value > static_cast<int>(CONNECTION_INFO_UNKNOWN) && |
| 284 value < static_cast<int>(NUM_OF_CONNECTION_INFOS)) { | 284 value < static_cast<int>(NUM_OF_CONNECTION_INFOS)) { |
| 285 connection_info = static_cast<ConnectionInfo>(value); | 285 connection_info = static_cast<ConnectionInfo>(value); |
| 286 } | 286 } |
| 287 } | 287 } |
| 288 | 288 |
| 289 // Read key_exchange_info | 289 // Read key_exchange_info |
| 290 if (flags & RESPONSE_INFO_HAS_KEY_EXCHANGE_INFO) { | 290 if (flags & RESPONSE_INFO_HAS_KEY_EXCHANGE_INFO) { |
| 291 int key_exchange_info; | 291 int key_exchange_info; |
| 292 if (!iter.ReadInt(&key_exchange_info)) | 292 if (!iter.ReadInt(&key_exchange_info)) |
| 293 return false; | 293 return false; |
| 294 ssl_info.key_exchange_info = key_exchange_info; | 294 ssl_info.key_exchange_info = key_exchange_info; |
| 295 } | 295 } |
| 296 | 296 |
| 297 was_fetched_via_spdy = (flags & RESPONSE_INFO_WAS_SPDY) != 0; | 297 was_fetched_via_spdy = (flags & RESPONSE_INFO_WAS_SPDY) != 0; |
| 298 | 298 |
| 299 was_npn_negotiated = (flags & RESPONSE_INFO_WAS_NPN) != 0; | 299 was_alpn_negotiated = (flags & RESPONSE_INFO_WAS_ALPN) != 0; |
| 300 | 300 |
| 301 was_fetched_via_proxy = (flags & RESPONSE_INFO_WAS_PROXY) != 0; | 301 was_fetched_via_proxy = (flags & RESPONSE_INFO_WAS_PROXY) != 0; |
| 302 | 302 |
| 303 *response_truncated = (flags & RESPONSE_INFO_TRUNCATED) != 0; | 303 *response_truncated = (flags & RESPONSE_INFO_TRUNCATED) != 0; |
| 304 | 304 |
| 305 did_use_http_auth = (flags & RESPONSE_INFO_USE_HTTP_AUTHENTICATION) != 0; | 305 did_use_http_auth = (flags & RESPONSE_INFO_USE_HTTP_AUTHENTICATION) != 0; |
| 306 | 306 |
| 307 unused_since_prefetch = (flags & RESPONSE_INFO_UNUSED_SINCE_PREFETCH) != 0; | 307 unused_since_prefetch = (flags & RESPONSE_INFO_UNUSED_SINCE_PREFETCH) != 0; |
| 308 | 308 |
| 309 ssl_info.pkp_bypassed = (flags & RESPONSE_INFO_PKP_BYPASSED) != 0; | 309 ssl_info.pkp_bypassed = (flags & RESPONSE_INFO_PKP_BYPASSED) != 0; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 324 flags |= RESPONSE_INFO_HAS_KEY_EXCHANGE_INFO; | 324 flags |= RESPONSE_INFO_HAS_KEY_EXCHANGE_INFO; |
| 325 if (ssl_info.connection_status != 0) | 325 if (ssl_info.connection_status != 0) |
| 326 flags |= RESPONSE_INFO_HAS_SSL_CONNECTION_STATUS; | 326 flags |= RESPONSE_INFO_HAS_SSL_CONNECTION_STATUS; |
| 327 } | 327 } |
| 328 if (vary_data.is_valid()) | 328 if (vary_data.is_valid()) |
| 329 flags |= RESPONSE_INFO_HAS_VARY_DATA; | 329 flags |= RESPONSE_INFO_HAS_VARY_DATA; |
| 330 if (response_truncated) | 330 if (response_truncated) |
| 331 flags |= RESPONSE_INFO_TRUNCATED; | 331 flags |= RESPONSE_INFO_TRUNCATED; |
| 332 if (was_fetched_via_spdy) | 332 if (was_fetched_via_spdy) |
| 333 flags |= RESPONSE_INFO_WAS_SPDY; | 333 flags |= RESPONSE_INFO_WAS_SPDY; |
| 334 if (was_npn_negotiated) { | 334 if (was_alpn_negotiated) { |
| 335 flags |= RESPONSE_INFO_WAS_NPN; | 335 flags |= RESPONSE_INFO_WAS_ALPN; |
| 336 flags |= RESPONSE_INFO_HAS_NPN_NEGOTIATED_PROTOCOL; | 336 flags |= RESPONSE_INFO_HAS_ALPN_NEGOTIATED_PROTOCOL; |
| 337 } | 337 } |
| 338 if (was_fetched_via_proxy) | 338 if (was_fetched_via_proxy) |
| 339 flags |= RESPONSE_INFO_WAS_PROXY; | 339 flags |= RESPONSE_INFO_WAS_PROXY; |
| 340 if (connection_info != CONNECTION_INFO_UNKNOWN) | 340 if (connection_info != CONNECTION_INFO_UNKNOWN) |
| 341 flags |= RESPONSE_INFO_HAS_CONNECTION_INFO; | 341 flags |= RESPONSE_INFO_HAS_CONNECTION_INFO; |
| 342 if (did_use_http_auth) | 342 if (did_use_http_auth) |
| 343 flags |= RESPONSE_INFO_USE_HTTP_AUTHENTICATION; | 343 flags |= RESPONSE_INFO_USE_HTTP_AUTHENTICATION; |
| 344 if (unused_since_prefetch) | 344 if (unused_since_prefetch) |
| 345 flags |= RESPONSE_INFO_UNUSED_SINCE_PREFETCH; | 345 flags |= RESPONSE_INFO_UNUSED_SINCE_PREFETCH; |
| 346 if (!ssl_info.signed_certificate_timestamps.empty()) | 346 if (!ssl_info.signed_certificate_timestamps.empty()) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 } | 383 } |
| 384 } | 384 } |
| 385 } | 385 } |
| 386 | 386 |
| 387 if (vary_data.is_valid()) | 387 if (vary_data.is_valid()) |
| 388 vary_data.Persist(pickle); | 388 vary_data.Persist(pickle); |
| 389 | 389 |
| 390 pickle->WriteString(socket_address.host()); | 390 pickle->WriteString(socket_address.host()); |
| 391 pickle->WriteUInt16(socket_address.port()); | 391 pickle->WriteUInt16(socket_address.port()); |
| 392 | 392 |
| 393 if (was_npn_negotiated) | 393 if (was_alpn_negotiated) |
| 394 pickle->WriteString(npn_negotiated_protocol); | 394 pickle->WriteString(alpn_negotiated_protocol); |
| 395 | 395 |
| 396 if (connection_info != CONNECTION_INFO_UNKNOWN) | 396 if (connection_info != CONNECTION_INFO_UNKNOWN) |
| 397 pickle->WriteInt(static_cast<int>(connection_info)); | 397 pickle->WriteInt(static_cast<int>(connection_info)); |
| 398 | 398 |
| 399 if (ssl_info.is_valid() && ssl_info.key_exchange_info != 0) | 399 if (ssl_info.is_valid() && ssl_info.key_exchange_info != 0) |
| 400 pickle->WriteInt(ssl_info.key_exchange_info); | 400 pickle->WriteInt(ssl_info.key_exchange_info); |
| 401 } | 401 } |
| 402 | 402 |
| 403 HttpResponseInfo::ConnectionInfo HttpResponseInfo::ConnectionInfoFromNextProto( | 403 HttpResponseInfo::ConnectionInfo HttpResponseInfo::ConnectionInfoFromNextProto( |
| 404 NextProto next_proto) { | 404 NextProto next_proto) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 case CONNECTION_INFO_HTTP1_0: | 445 case CONNECTION_INFO_HTTP1_0: |
| 446 return "http/1.0"; | 446 return "http/1.0"; |
| 447 case NUM_OF_CONNECTION_INFOS: | 447 case NUM_OF_CONNECTION_INFOS: |
| 448 break; | 448 break; |
| 449 } | 449 } |
| 450 NOTREACHED(); | 450 NOTREACHED(); |
| 451 return ""; | 451 return ""; |
| 452 } | 452 } |
| 453 | 453 |
| 454 } // namespace net | 454 } // namespace net |
| OLD | NEW |