1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
|
/*
* Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ResourceResponse_h
#define ResourceResponse_h
#include "platform/PlatformExport.h"
#include "platform/blob/BlobData.h"
#include "platform/network/HTTPHeaderMap.h"
#include "platform/network/HTTPParsers.h"
#include "platform/network/ResourceLoadInfo.h"
#include "platform/network/ResourceLoadTiming.h"
#include "platform/weborigin/KURL.h"
#include "public/platform/WebURLResponse.h"
#include "public/platform/modules/serviceworker/WebServiceWorkerResponseType.h"
#include "wtf/RefCounted.h"
#include "wtf/RefPtr.h"
#include "wtf/Vector.h"
#include "wtf/text/CString.h"
namespace blink {
struct CrossThreadResourceResponseData;
class PLATFORM_EXPORT ResourceResponse final {
DISALLOW_NEW_EXCEPT_PLACEMENT_NEW();
public:
enum HTTPVersion {
HTTPVersionUnknown,
HTTPVersion_0_9,
HTTPVersion_1_0,
HTTPVersion_1_1,
HTTPVersion_2_0
};
enum SecurityStyle {
SecurityStyleUnknown,
SecurityStyleUnauthenticated,
SecurityStyleAuthenticationBroken,
SecurityStyleWarning,
SecurityStyleAuthenticated
};
class PLATFORM_EXPORT SignedCertificateTimestamp final {
public:
SignedCertificateTimestamp(String status,
String origin,
String logDescription,
String logId,
int64_t timestamp,
String hashAlgorithm,
String signatureAlgorithm,
String signatureData)
: m_status(status),
m_origin(origin),
m_logDescription(logDescription),
m_logId(logId),
m_timestamp(timestamp),
m_hashAlgorithm(hashAlgorithm),
m_signatureAlgorithm(signatureAlgorithm),
m_signatureData(signatureData) {}
explicit SignedCertificateTimestamp(
const struct blink::WebURLResponse::SignedCertificateTimestamp&);
SignedCertificateTimestamp isolatedCopy() const;
String m_status;
String m_origin;
String m_logDescription;
String m_logId;
int64_t m_timestamp;
String m_hashAlgorithm;
String m_signatureAlgorithm;
String m_signatureData;
};
using SignedCertificateTimestampList =
WTF::Vector<SignedCertificateTimestamp>;
struct SecurityDetails {
DISALLOW_NEW();
SecurityDetails() : validFrom(0), validTo(0) {}
// All strings are human-readable values.
String protocol;
// keyExchange is the empty string if not applicable for the connection's
// protocol.
String keyExchange;
// keyExchangeGroup is the empty string if not applicable for the
// connection's key exchange.
String keyExchangeGroup;
String cipher;
// mac is the empty string when the connection cipher suite does not
// have a separate MAC value (i.e. if the cipher suite is AEAD).
String mac;
String subjectName;
Vector<String> sanList;
String issuer;
time_t validFrom;
time_t validTo;
// DER-encoded X509Certificate certificate chain.
Vector<AtomicString> certificate;
SignedCertificateTimestampList sctList;
};
class ExtraData : public RefCounted<ExtraData> {
public:
virtual ~ExtraData() {}
};
explicit ResourceResponse(CrossThreadResourceResponseData*);
// Gets a copy of the data suitable for passing to another thread.
std::unique_ptr<CrossThreadResourceResponseData> copyData() const;
ResourceResponse();
ResourceResponse(const KURL&,
const AtomicString& mimeType,
long long expectedLength,
const AtomicString& textEncodingName,
const String& filename);
ResourceResponse(const ResourceResponse&);
ResourceResponse& operator=(const ResourceResponse&);
bool isNull() const { return m_isNull; }
bool isHTTP() const;
// The URL of the resource. Note that if a service worker responded to the
// request for this resource, it may have fetched an entirely different URL
// and responded with that resource. wasFetchedViaServiceWorker() and
// originalURLViaServiceWorker() can be used to determine whether and how a
// service worker responded to the request. Example service worker code:
//
// onfetch = (event => {
// if (event.request.url == 'https://abc.com')
// event.respondWith(fetch('https://def.com'));
// });
//
// If this service worker responds to an "https://abc.com" request, then for
// the resulting ResourceResponse, url() is "https://abc.com",
// wasFetchedViaServiceWorker() is true, and originalURLViaServiceWorker() is
// "https://def.com".
const KURL& url() const;
void setURL(const KURL&);
const AtomicString& mimeType() const;
void setMimeType(const AtomicString&);
long long expectedContentLength() const;
void setExpectedContentLength(long long);
const AtomicString& textEncodingName() const;
void setTextEncodingName(const AtomicString&);
// FIXME: Should compute this on the fly.
// There should not be a setter exposed, as suggested file name is determined
// based on other headers in a manner that WebCore does not necessarily know
// about.
const String& suggestedFilename() const;
void setSuggestedFilename(const String&);
int httpStatusCode() const;
void setHTTPStatusCode(int);
const AtomicString& httpStatusText() const;
void setHTTPStatusText(const AtomicString&);
const AtomicString& httpHeaderField(const AtomicString& name) const;
void setHTTPHeaderField(const AtomicString& name, const AtomicString& value);
void addHTTPHeaderField(const AtomicString& name, const AtomicString& value);
void clearHTTPHeaderField(const AtomicString& name);
const HTTPHeaderMap& httpHeaderFields() const;
bool isMultipart() const { return mimeType() == "multipart/x-mixed-replace"; }
bool isAttachment() const;
// FIXME: These are used by PluginStream on some platforms. Calculations may
// differ from just returning plain Last-Modified header.
// Leaving it for now but this should go away in favor of generic solution.
void setLastModifiedDate(time_t);
time_t lastModifiedDate() const;
// These functions return parsed values of the corresponding response headers.
// NaN means that the header was not present or had invalid value.
bool cacheControlContainsNoCache() const;
bool cacheControlContainsNoStore() const;
bool cacheControlContainsMustRevalidate() const;
bool hasCacheValidatorFields() const;
double cacheControlMaxAge() const;
double cacheControlStaleWhileRevalidate() const;
double date() const;
double age() const;
double expires() const;
double lastModified() const;
unsigned connectionID() const;
void setConnectionID(unsigned);
bool connectionReused() const;
void setConnectionReused(bool);
bool wasCached() const;
void setWasCached(bool);
ResourceLoadTiming* resourceLoadTiming() const;
void setResourceLoadTiming(PassRefPtr<ResourceLoadTiming>);
PassRefPtr<ResourceLoadInfo> resourceLoadInfo() const;
void setResourceLoadInfo(PassRefPtr<ResourceLoadInfo>);
HTTPVersion httpVersion() const { return m_httpVersion; }
void setHTTPVersion(HTTPVersion version) { m_httpVersion = version; }
bool hasMajorCertificateErrors() const { return m_hasMajorCertificateErrors; }
void setHasMajorCertificateErrors(bool hasMajorCertificateErrors) {
m_hasMajorCertificateErrors = hasMajorCertificateErrors;
}
SecurityStyle getSecurityStyle() const { return m_securityStyle; }
void setSecurityStyle(SecurityStyle securityStyle) {
m_securityStyle = securityStyle;
}
const SecurityDetails* getSecurityDetails() const {
return &m_securityDetails;
}
void setSecurityDetails(const String& protocol,
const String& keyExchange,
const String& keyExchangeGroup,
const String& cipher,
const String& mac,
const String& subjectName,
const Vector<String>& sanList,
const String& issuer,
time_t validFrom,
time_t validTo,
const Vector<AtomicString>& certificate,
const SignedCertificateTimestampList& sctList);
long long appCacheID() const { return m_appCacheID; }
void setAppCacheID(long long id) { m_appCacheID = id; }
const KURL& appCacheManifestURL() const { return m_appCacheManifestURL; }
void setAppCacheManifestURL(const KURL& url) { m_appCacheManifestURL = url; }
bool wasFetchedViaSPDY() const { return m_wasFetchedViaSPDY; }
void setWasFetchedViaSPDY(bool value) { m_wasFetchedViaSPDY = value; }
bool wasNpnNegotiated() const { return m_wasNpnNegotiated; }
void setWasNpnNegotiated(bool value) { m_wasNpnNegotiated = value; }
bool wasAlternateProtocolAvailable() const {
return m_wasAlternateProtocolAvailable;
}
void setWasAlternateProtocolAvailable(bool value) {
m_wasAlternateProtocolAvailable = value;
}
// See ServiceWorkerResponseInfo::was_fetched_via_service_worker.
bool wasFetchedViaServiceWorker() const {
return m_wasFetchedViaServiceWorker;
}
void setWasFetchedViaServiceWorker(bool value) {
m_wasFetchedViaServiceWorker = value;
}
bool wasFetchedViaForeignFetch() const { return m_wasFetchedViaForeignFetch; }
void setWasFetchedViaForeignFetch(bool value) {
m_wasFetchedViaForeignFetch = value;
}
// See ServiceWorkerResponseInfo::was_fallback_required.
bool wasFallbackRequiredByServiceWorker() const {
return m_wasFallbackRequiredByServiceWorker;
}
void setWasFallbackRequiredByServiceWorker(bool value) {
m_wasFallbackRequiredByServiceWorker = value;
}
WebServiceWorkerResponseType serviceWorkerResponseType() const {
return m_serviceWorkerResponseType;
}
void setServiceWorkerResponseType(WebServiceWorkerResponseType value) {
m_serviceWorkerResponseType = value;
}
// See ServiceWorkerResponseInfo::url_list_via_service_worker.
const Vector<KURL>& urlListViaServiceWorker() const {
return m_urlListViaServiceWorker;
}
void setURLListViaServiceWorker(const Vector<KURL>& urlList) {
m_urlListViaServiceWorker = urlList;
}
// Returns the last URL of urlListViaServiceWorker if exists. Otherwise
// returns an empty URL.
KURL originalURLViaServiceWorker() const;
const Vector<char>& multipartBoundary() const { return m_multipartBoundary; }
void setMultipartBoundary(const char* bytes, size_t size) {
m_multipartBoundary.clear();
m_multipartBoundary.append(bytes, size);
}
const String& cacheStorageCacheName() const {
return m_cacheStorageCacheName;
}
void setCacheStorageCacheName(const String& cacheStorageCacheName) {
m_cacheStorageCacheName = cacheStorageCacheName;
}
const Vector<String>& corsExposedHeaderNames() const {
return m_corsExposedHeaderNames;
}
void setCorsExposedHeaderNames(const Vector<String>& headerNames) {
m_corsExposedHeaderNames = headerNames;
}
bool didServiceWorkerNavigationPreload() const {
return m_didServiceWorkerNavigationPreload;
}
void setDidServiceWorkerNavigationPreload(bool value) {
m_didServiceWorkerNavigationPreload = value;
}
int64_t responseTime() const { return m_responseTime; }
void setResponseTime(int64_t responseTime) { m_responseTime = responseTime; }
const AtomicString& remoteIPAddress() const { return m_remoteIPAddress; }
void setRemoteIPAddress(const AtomicString& value) {
m_remoteIPAddress = value;
}
unsigned short remotePort() const { return m_remotePort; }
void setRemotePort(unsigned short value) { m_remotePort = value; }
long long encodedDataLength() const { return m_encodedDataLength; }
void setEncodedDataLength(long long value);
long long encodedBodyLength() const { return m_encodedBodyLength; }
void addToEncodedBodyLength(long long value);
long long decodedBodyLength() const { return m_decodedBodyLength; }
void addToDecodedBodyLength(long long value);
const String& downloadedFilePath() const { return m_downloadedFilePath; }
void setDownloadedFilePath(const String&);
// Extra data associated with this response.
ExtraData* getExtraData() const { return m_extraData.get(); }
void setExtraData(PassRefPtr<ExtraData> extraData) {
m_extraData = extraData;
}
unsigned memoryUsage() const {
// average size, mostly due to URL and Header Map strings
return 1280;
}
// PlzNavigate: Even if there is redirections, only one
// ResourceResponse is built: the final response.
// The redirect response chain can be accessed by this function.
const Vector<ResourceResponse>& redirectResponses() const {
return m_redirectResponses;
}
void appendRedirectResponse(const ResourceResponse&);
// This method doesn't compare the all members.
static bool compare(const ResourceResponse&, const ResourceResponse&);
private:
void updateHeaderParsedState(const AtomicString& name);
KURL m_url;
AtomicString m_mimeType;
long long m_expectedContentLength;
AtomicString m_textEncodingName;
String m_suggestedFilename;
int m_httpStatusCode;
AtomicString m_httpStatusText;
HTTPHeaderMap m_httpHeaderFields;
time_t m_lastModifiedDate;
bool m_wasCached : 1;
unsigned m_connectionID;
bool m_connectionReused : 1;
RefPtr<ResourceLoadTiming> m_resourceLoadTiming;
RefPtr<ResourceLoadInfo> m_resourceLoadInfo;
bool m_isNull : 1;
mutable CacheControlHeader m_cacheControlHeader;
mutable bool m_haveParsedAgeHeader : 1;
mutable bool m_haveParsedDateHeader : 1;
mutable bool m_haveParsedExpiresHeader : 1;
mutable bool m_haveParsedLastModifiedHeader : 1;
mutable double m_age;
mutable double m_date;
mutable double m_expires;
mutable double m_lastModified;
// True if the resource was retrieved by the embedder in spite of
// certificate errors.
bool m_hasMajorCertificateErrors;
// The security style of the resource.
// This only contains a valid value when the DevTools Network domain is
// enabled. (Otherwise, it contains a default value of Unknown.)
SecurityStyle m_securityStyle;
// Security details of this request's connection.
// If m_securityStyle is Unknown or Unauthenticated, this does not contain
// valid data.
SecurityDetails m_securityDetails;
// HTTP version used in the response, if known.
HTTPVersion m_httpVersion;
// The id of the appcache this response was retrieved from, or zero if
// the response was not retrieved from an appcache.
long long m_appCacheID;
// The manifest url of the appcache this response was retrieved from, if any.
// Note: only valid for main resource responses.
KURL m_appCacheManifestURL;
// The multipart boundary of this response.
Vector<char> m_multipartBoundary;
// Was the resource fetched over SPDY. See http://dev.chromium.org/spdy
bool m_wasFetchedViaSPDY;
// Was the resource fetched over a channel which used
// TLS/Next-Protocol-Negotiation (also SPDY related).
bool m_wasNpnNegotiated;
// Was the resource fetched over a channel which specified
// "Alternate-Protocol"
// (e.g.: Alternate-Protocol: 443:npn-spdy/1).
bool m_wasAlternateProtocolAvailable;
// Was the resource fetched over an explicit proxy (HTTP, SOCKS, etc).
bool m_wasFetchedViaProxy;
// Was the resource fetched over a ServiceWorker.
bool m_wasFetchedViaServiceWorker;
// Was the resource fetched using a foreign fetch service worker.
bool m_wasFetchedViaForeignFetch;
// Was the fallback request with skip service worker flag required.
bool m_wasFallbackRequiredByServiceWorker;
// The type of the response which was fetched by the ServiceWorker.
WebServiceWorkerResponseType m_serviceWorkerResponseType;
// The URL list of the response which was fetched by the ServiceWorker.
// This is empty if the response was created inside the ServiceWorker.
Vector<KURL> m_urlListViaServiceWorker;
// The cache name of the CacheStorage from where the response is served via
// the ServiceWorker. Null if the response isn't from the CacheStorage.
String m_cacheStorageCacheName;
// The headers that should be exposed according to CORS. Only guaranteed
// to be set if the response was fetched by a ServiceWorker.
Vector<String> m_corsExposedHeaderNames;
// True if service worker navigation preload was performed due to
// the request for this resource.
bool m_didServiceWorkerNavigationPreload;
// The time at which the response headers were received. For cached
// responses, this time could be "far" in the past.
int64_t m_responseTime;
// Remote IP address of the socket which fetched this resource.
AtomicString m_remoteIPAddress;
// Remote port number of the socket which fetched this resource.
unsigned short m_remotePort;
// Size of the response in bytes prior to decompression.
long long m_encodedDataLength;
// Size of the response body in bytes prior to decompression.
long long m_encodedBodyLength;
// Sizes of the response body in bytes after any content-encoding is
// removed.
long long m_decodedBodyLength;
// The downloaded file path if the load streamed to a file.
String m_downloadedFilePath;
// The handle to the downloaded file to ensure the underlying file will not
// be deleted.
RefPtr<BlobDataHandle> m_downloadedFileHandle;
// ExtraData associated with the response.
RefPtr<ExtraData> m_extraData;
// PlzNavigate: the redirect responses are transmitted
// inside the final response.
Vector<ResourceResponse> m_redirectResponses;
};
inline bool operator==(const ResourceResponse& a, const ResourceResponse& b) {
return ResourceResponse::compare(a, b);
}
inline bool operator!=(const ResourceResponse& a, const ResourceResponse& b) {
return !(a == b);
}
struct CrossThreadResourceResponseData {
WTF_MAKE_NONCOPYABLE(CrossThreadResourceResponseData);
USING_FAST_MALLOC(CrossThreadResourceResponseData);
public:
CrossThreadResourceResponseData() {}
KURL m_url;
String m_mimeType;
long long m_expectedContentLength;
String m_textEncodingName;
String m_suggestedFilename;
int m_httpStatusCode;
String m_httpStatusText;
std::unique_ptr<CrossThreadHTTPHeaderMapData> m_httpHeaders;
time_t m_lastModifiedDate;
RefPtr<ResourceLoadTiming> m_resourceLoadTiming;
bool m_hasMajorCertificateErrors;
ResourceResponse::SecurityStyle m_securityStyle;
ResourceResponse::SecurityDetails m_securityDetails;
// This is |certificate| from SecurityDetails since that structure should
// use an AtomicString but this temporary structure is sent across threads.
Vector<String> m_certificate;
ResourceResponse::HTTPVersion m_httpVersion;
long long m_appCacheID;
KURL m_appCacheManifestURL;
Vector<char> m_multipartBoundary;
bool m_wasFetchedViaSPDY;
bool m_wasNpnNegotiated;
bool m_wasAlternateProtocolAvailable;
bool m_wasFetchedViaProxy;
bool m_wasFetchedViaServiceWorker;
bool m_wasFetchedViaForeignFetch;
bool m_wasFallbackRequiredByServiceWorker;
WebServiceWorkerResponseType m_serviceWorkerResponseType;
Vector<KURL> m_urlListViaServiceWorker;
String m_cacheStorageCacheName;
bool m_didServiceWorkerNavigationPreload;
int64_t m_responseTime;
String m_remoteIPAddress;
unsigned short m_remotePort;
long long m_encodedDataLength;
long long m_encodedBodyLength;
long long m_decodedBodyLength;
String m_downloadedFilePath;
RefPtr<BlobDataHandle> m_downloadedFileHandle;
};
} // namespace blink
#endif // ResourceResponse_h
|