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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 // This bit is set if the response info has connection info. | 85 // This bit is set if the response info has connection info. |
86 RESPONSE_INFO_HAS_CONNECTION_INFO = 1 << 18, | 86 RESPONSE_INFO_HAS_CONNECTION_INFO = 1 << 18, |
87 | 87 |
88 // This bit is set if the request has http authentication. | 88 // This bit is set if the request has http authentication. |
89 RESPONSE_INFO_USE_HTTP_AUTHENTICATION = 1 << 19, | 89 RESPONSE_INFO_USE_HTTP_AUTHENTICATION = 1 << 19, |
90 | 90 |
91 // This bit is set if ssl_info has SCTs. | 91 // This bit is set if ssl_info has SCTs. |
92 RESPONSE_INFO_HAS_SIGNED_CERTIFICATE_TIMESTAMPS = 1 << 20, | 92 RESPONSE_INFO_HAS_SIGNED_CERTIFICATE_TIMESTAMPS = 1 << 20, |
93 | 93 |
| 94 // This bit is set if the response was received via a ServiceWorker . |
| 95 RESPONSE_INFO_WAS_SERVICE_WORKER = 1 << 21, |
| 96 |
94 // TODO(darin): Add other bits to indicate alternate request methods. | 97 // TODO(darin): Add other bits to indicate alternate request methods. |
95 // For now, we don't support storing those. | 98 // For now, we don't support storing those. |
96 }; | 99 }; |
97 | 100 |
98 HttpResponseInfo::HttpResponseInfo() | 101 HttpResponseInfo::HttpResponseInfo() |
99 : was_cached(false), | 102 : was_cached(false), |
100 server_data_unavailable(false), | 103 server_data_unavailable(false), |
101 network_accessed(false), | 104 network_accessed(false), |
102 was_fetched_via_spdy(false), | 105 was_fetched_via_spdy(false), |
103 was_npn_negotiated(false), | 106 was_npn_negotiated(false), |
104 was_fetched_via_proxy(false), | 107 was_fetched_via_proxy(false), |
105 did_use_http_auth(false), | 108 did_use_http_auth(false), |
| 109 was_fetched_via_service_worker(false), |
106 connection_info(CONNECTION_INFO_UNKNOWN) { | 110 connection_info(CONNECTION_INFO_UNKNOWN) { |
107 } | 111 } |
108 | 112 |
109 HttpResponseInfo::HttpResponseInfo(const HttpResponseInfo& rhs) | 113 HttpResponseInfo::HttpResponseInfo(const HttpResponseInfo& rhs) |
110 : was_cached(rhs.was_cached), | 114 : was_cached(rhs.was_cached), |
111 server_data_unavailable(rhs.server_data_unavailable), | 115 server_data_unavailable(rhs.server_data_unavailable), |
112 network_accessed(rhs.network_accessed), | 116 network_accessed(rhs.network_accessed), |
113 was_fetched_via_spdy(rhs.was_fetched_via_spdy), | 117 was_fetched_via_spdy(rhs.was_fetched_via_spdy), |
114 was_npn_negotiated(rhs.was_npn_negotiated), | 118 was_npn_negotiated(rhs.was_npn_negotiated), |
115 was_fetched_via_proxy(rhs.was_fetched_via_proxy), | 119 was_fetched_via_proxy(rhs.was_fetched_via_proxy), |
116 proxy_server(rhs.proxy_server), | 120 proxy_server(rhs.proxy_server), |
117 did_use_http_auth(rhs.did_use_http_auth), | 121 did_use_http_auth(rhs.did_use_http_auth), |
| 122 was_fetched_via_service_worker(rhs.was_fetched_via_service_worker), |
| 123 original_url_via_service_worker(rhs.original_url_via_service_worker), |
118 socket_address(rhs.socket_address), | 124 socket_address(rhs.socket_address), |
119 npn_negotiated_protocol(rhs.npn_negotiated_protocol), | 125 npn_negotiated_protocol(rhs.npn_negotiated_protocol), |
120 connection_info(rhs.connection_info), | 126 connection_info(rhs.connection_info), |
121 request_time(rhs.request_time), | 127 request_time(rhs.request_time), |
122 response_time(rhs.response_time), | 128 response_time(rhs.response_time), |
123 auth_challenge(rhs.auth_challenge), | 129 auth_challenge(rhs.auth_challenge), |
124 cert_request_info(rhs.cert_request_info), | 130 cert_request_info(rhs.cert_request_info), |
125 ssl_info(rhs.ssl_info), | 131 ssl_info(rhs.ssl_info), |
126 headers(rhs.headers), | 132 headers(rhs.headers), |
127 vary_data(rhs.vary_data), | 133 vary_data(rhs.vary_data), |
128 metadata(rhs.metadata) { | 134 metadata(rhs.metadata) { |
129 } | 135 } |
130 | 136 |
131 HttpResponseInfo::~HttpResponseInfo() { | 137 HttpResponseInfo::~HttpResponseInfo() { |
132 } | 138 } |
133 | 139 |
134 HttpResponseInfo& HttpResponseInfo::operator=(const HttpResponseInfo& rhs) { | 140 HttpResponseInfo& HttpResponseInfo::operator=(const HttpResponseInfo& rhs) { |
135 was_cached = rhs.was_cached; | 141 was_cached = rhs.was_cached; |
136 server_data_unavailable = rhs.server_data_unavailable; | 142 server_data_unavailable = rhs.server_data_unavailable; |
137 network_accessed = rhs.network_accessed; | 143 network_accessed = rhs.network_accessed; |
138 was_fetched_via_spdy = rhs.was_fetched_via_spdy; | 144 was_fetched_via_spdy = rhs.was_fetched_via_spdy; |
139 proxy_server = rhs.proxy_server; | 145 proxy_server = rhs.proxy_server; |
140 was_npn_negotiated = rhs.was_npn_negotiated; | 146 was_npn_negotiated = rhs.was_npn_negotiated; |
141 was_fetched_via_proxy = rhs.was_fetched_via_proxy; | 147 was_fetched_via_proxy = rhs.was_fetched_via_proxy; |
142 did_use_http_auth = rhs.did_use_http_auth; | 148 did_use_http_auth = rhs.did_use_http_auth; |
| 149 was_fetched_via_service_worker = rhs.was_fetched_via_service_worker; |
| 150 original_url_via_service_worker = rhs.original_url_via_service_worker; |
143 socket_address = rhs.socket_address; | 151 socket_address = rhs.socket_address; |
144 npn_negotiated_protocol = rhs.npn_negotiated_protocol; | 152 npn_negotiated_protocol = rhs.npn_negotiated_protocol; |
145 connection_info = rhs.connection_info; | 153 connection_info = rhs.connection_info; |
146 request_time = rhs.request_time; | 154 request_time = rhs.request_time; |
147 response_time = rhs.response_time; | 155 response_time = rhs.response_time; |
148 auth_challenge = rhs.auth_challenge; | 156 auth_challenge = rhs.auth_challenge; |
149 cert_request_info = rhs.cert_request_info; | 157 cert_request_info = rhs.cert_request_info; |
150 ssl_info = rhs.ssl_info; | 158 ssl_info = rhs.ssl_info; |
151 headers = rhs.headers; | 159 headers = rhs.headers; |
152 vary_data = rhs.vary_data; | 160 vary_data = rhs.vary_data; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 int value; | 268 int value; |
261 if (!pickle.ReadInt(&iter, &value)) | 269 if (!pickle.ReadInt(&iter, &value)) |
262 return false; | 270 return false; |
263 | 271 |
264 if (value > static_cast<int>(CONNECTION_INFO_UNKNOWN) && | 272 if (value > static_cast<int>(CONNECTION_INFO_UNKNOWN) && |
265 value < static_cast<int>(NUM_OF_CONNECTION_INFOS)) { | 273 value < static_cast<int>(NUM_OF_CONNECTION_INFOS)) { |
266 connection_info = static_cast<ConnectionInfo>(value); | 274 connection_info = static_cast<ConnectionInfo>(value); |
267 } | 275 } |
268 } | 276 } |
269 | 277 |
| 278 // Read ServiceWorker info. |
| 279 if (flags & RESPONSE_INFO_WAS_SERVICE_WORKER) { |
| 280 std::string original_url; |
| 281 if (!pickle.ReadString(&iter, &original_url)) |
| 282 return false; |
| 283 original_url_via_service_worker = GURL(original_url); |
| 284 } |
| 285 |
270 was_fetched_via_spdy = (flags & RESPONSE_INFO_WAS_SPDY) != 0; | 286 was_fetched_via_spdy = (flags & RESPONSE_INFO_WAS_SPDY) != 0; |
271 | 287 |
272 was_npn_negotiated = (flags & RESPONSE_INFO_WAS_NPN) != 0; | 288 was_npn_negotiated = (flags & RESPONSE_INFO_WAS_NPN) != 0; |
273 | 289 |
274 was_fetched_via_proxy = (flags & RESPONSE_INFO_WAS_PROXY) != 0; | 290 was_fetched_via_proxy = (flags & RESPONSE_INFO_WAS_PROXY) != 0; |
275 | 291 |
276 *response_truncated = (flags & RESPONSE_INFO_TRUNCATED) != 0; | 292 *response_truncated = (flags & RESPONSE_INFO_TRUNCATED) != 0; |
277 | 293 |
278 did_use_http_auth = (flags & RESPONSE_INFO_USE_HTTP_AUTHENTICATION) != 0; | 294 did_use_http_auth = (flags & RESPONSE_INFO_USE_HTTP_AUTHENTICATION) != 0; |
279 | 295 |
| 296 was_fetched_via_service_worker = |
| 297 (flags & RESPONSE_INFO_WAS_SERVICE_WORKER) != 0; |
| 298 |
280 return true; | 299 return true; |
281 } | 300 } |
282 | 301 |
283 void HttpResponseInfo::Persist(Pickle* pickle, | 302 void HttpResponseInfo::Persist(Pickle* pickle, |
284 bool skip_transient_headers, | 303 bool skip_transient_headers, |
285 bool response_truncated) const { | 304 bool response_truncated) const { |
286 int flags = RESPONSE_INFO_VERSION; | 305 int flags = RESPONSE_INFO_VERSION; |
287 if (ssl_info.is_valid()) { | 306 if (ssl_info.is_valid()) { |
288 flags |= RESPONSE_INFO_HAS_CERT; | 307 flags |= RESPONSE_INFO_HAS_CERT; |
289 flags |= RESPONSE_INFO_HAS_CERT_STATUS; | 308 flags |= RESPONSE_INFO_HAS_CERT_STATUS; |
(...skipping 13 matching lines...) Expand all Loading... |
303 flags |= RESPONSE_INFO_HAS_NPN_NEGOTIATED_PROTOCOL; | 322 flags |= RESPONSE_INFO_HAS_NPN_NEGOTIATED_PROTOCOL; |
304 } | 323 } |
305 if (was_fetched_via_proxy) | 324 if (was_fetched_via_proxy) |
306 flags |= RESPONSE_INFO_WAS_PROXY; | 325 flags |= RESPONSE_INFO_WAS_PROXY; |
307 if (connection_info != CONNECTION_INFO_UNKNOWN) | 326 if (connection_info != CONNECTION_INFO_UNKNOWN) |
308 flags |= RESPONSE_INFO_HAS_CONNECTION_INFO; | 327 flags |= RESPONSE_INFO_HAS_CONNECTION_INFO; |
309 if (did_use_http_auth) | 328 if (did_use_http_auth) |
310 flags |= RESPONSE_INFO_USE_HTTP_AUTHENTICATION; | 329 flags |= RESPONSE_INFO_USE_HTTP_AUTHENTICATION; |
311 if (!ssl_info.signed_certificate_timestamps.empty()) | 330 if (!ssl_info.signed_certificate_timestamps.empty()) |
312 flags |= RESPONSE_INFO_HAS_SIGNED_CERTIFICATE_TIMESTAMPS; | 331 flags |= RESPONSE_INFO_HAS_SIGNED_CERTIFICATE_TIMESTAMPS; |
| 332 if (was_fetched_via_service_worker) |
| 333 flags |= RESPONSE_INFO_WAS_SERVICE_WORKER; |
313 | 334 |
314 pickle->WriteInt(flags); | 335 pickle->WriteInt(flags); |
315 pickle->WriteInt64(request_time.ToInternalValue()); | 336 pickle->WriteInt64(request_time.ToInternalValue()); |
316 pickle->WriteInt64(response_time.ToInternalValue()); | 337 pickle->WriteInt64(response_time.ToInternalValue()); |
317 | 338 |
318 net::HttpResponseHeaders::PersistOptions persist_options = | 339 net::HttpResponseHeaders::PersistOptions persist_options = |
319 net::HttpResponseHeaders::PERSIST_RAW; | 340 net::HttpResponseHeaders::PERSIST_RAW; |
320 | 341 |
321 if (skip_transient_headers) { | 342 if (skip_transient_headers) { |
322 persist_options = | 343 persist_options = |
(...skipping 29 matching lines...) Expand all Loading... |
352 vary_data.Persist(pickle); | 373 vary_data.Persist(pickle); |
353 | 374 |
354 pickle->WriteString(socket_address.host()); | 375 pickle->WriteString(socket_address.host()); |
355 pickle->WriteUInt16(socket_address.port()); | 376 pickle->WriteUInt16(socket_address.port()); |
356 | 377 |
357 if (was_npn_negotiated) | 378 if (was_npn_negotiated) |
358 pickle->WriteString(npn_negotiated_protocol); | 379 pickle->WriteString(npn_negotiated_protocol); |
359 | 380 |
360 if (connection_info != CONNECTION_INFO_UNKNOWN) | 381 if (connection_info != CONNECTION_INFO_UNKNOWN) |
361 pickle->WriteInt(static_cast<int>(connection_info)); | 382 pickle->WriteInt(static_cast<int>(connection_info)); |
| 383 |
| 384 if (was_fetched_via_service_worker) |
| 385 pickle->WriteString(original_url_via_service_worker.spec()); |
362 } | 386 } |
363 | 387 |
364 HttpResponseInfo::ConnectionInfo HttpResponseInfo::ConnectionInfoFromNextProto( | 388 HttpResponseInfo::ConnectionInfo HttpResponseInfo::ConnectionInfoFromNextProto( |
365 NextProto next_proto) { | 389 NextProto next_proto) { |
366 switch (next_proto) { | 390 switch (next_proto) { |
367 case kProtoDeprecatedSPDY2: | 391 case kProtoDeprecatedSPDY2: |
368 return CONNECTION_INFO_DEPRECATED_SPDY2; | 392 return CONNECTION_INFO_DEPRECATED_SPDY2; |
369 case kProtoSPDY3: | 393 case kProtoSPDY3: |
370 case kProtoSPDY31: | 394 case kProtoSPDY31: |
371 return CONNECTION_INFO_SPDY3; | 395 return CONNECTION_INFO_SPDY3; |
(...skipping 30 matching lines...) Expand all Loading... |
402 case CONNECTION_INFO_QUIC1_SPDY3: | 426 case CONNECTION_INFO_QUIC1_SPDY3: |
403 return "quic/1+spdy/3"; | 427 return "quic/1+spdy/3"; |
404 case NUM_OF_CONNECTION_INFOS: | 428 case NUM_OF_CONNECTION_INFOS: |
405 break; | 429 break; |
406 } | 430 } |
407 NOTREACHED(); | 431 NOTREACHED(); |
408 return ""; | 432 return ""; |
409 } | 433 } |
410 | 434 |
411 } // namespace net | 435 } // namespace net |
OLD | NEW |