1 | /* |
2 | * Copyright (C) 2014-2016 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include <pal/SessionID.h> |
29 | #include <wtf/Markable.h> |
30 | #include <wtf/WallTime.h> |
31 | |
32 | namespace WebCore { |
33 | |
34 | class CookieJar; |
35 | class ; |
36 | class NetworkStorageSession; |
37 | class ResourceRequest; |
38 | class ResourceResponse; |
39 | |
40 | struct RedirectChainCacheStatus { |
41 | enum class Status : uint8_t { |
42 | NoRedirection, |
43 | NotCachedRedirection, |
44 | CachedRedirection |
45 | }; |
46 | RedirectChainCacheStatus() |
47 | : endOfValidity(WallTime::infinity()) |
48 | , status(Status::NoRedirection) |
49 | { } |
50 | WallTime endOfValidity; |
51 | Status status; |
52 | }; |
53 | |
54 | WEBCORE_EXPORT Seconds computeCurrentAge(const ResourceResponse&, WallTime responseTimestamp); |
55 | WEBCORE_EXPORT Seconds computeFreshnessLifetimeForHTTPFamily(const ResourceResponse&, WallTime responseTimestamp); |
56 | WEBCORE_EXPORT void (ResourceResponse&, const ResourceResponse& validatingResponse); |
57 | WEBCORE_EXPORT void updateRedirectChainStatus(RedirectChainCacheStatus&, const ResourceResponse&); |
58 | |
59 | enum ReuseExpiredRedirectionOrNot { DoNotReuseExpiredRedirection, ReuseExpiredRedirection }; |
60 | WEBCORE_EXPORT bool redirectChainAllowsReuse(RedirectChainCacheStatus, ReuseExpiredRedirectionOrNot); |
61 | |
62 | struct CacheControlDirectives { |
63 | constexpr CacheControlDirectives() |
64 | : noCache(false) |
65 | , noStore(false) |
66 | , mustRevalidate(false) |
67 | , immutable(false) |
68 | { } |
69 | |
70 | Markable<Seconds, Seconds::MarkableTraits> maxAge; |
71 | Markable<Seconds, Seconds::MarkableTraits> maxStale; |
72 | bool noCache : 1; |
73 | bool noStore : 1; |
74 | bool mustRevalidate : 1; |
75 | bool immutable : 1; |
76 | }; |
77 | WEBCORE_EXPORT CacheControlDirectives (const HTTPHeaderMap&); |
78 | |
79 | WEBCORE_EXPORT Vector<std::pair<String, String>> (NetworkStorageSession&, const ResourceRequest&, const ResourceResponse&); |
80 | WEBCORE_EXPORT Vector<std::pair<String, String>> (const CookieJar*, const ResourceRequest&, const ResourceResponse&, const PAL::SessionID&); |
81 | WEBCORE_EXPORT bool (NetworkStorageSession&, const Vector<std::pair<String, String>>& , const ResourceRequest&); |
82 | WEBCORE_EXPORT bool (const CookieJar*, const Vector<std::pair<String, String>>& , const ResourceRequest&, const PAL::SessionID&); |
83 | |
84 | WEBCORE_EXPORT bool isStatusCodeCacheableByDefault(int statusCode); |
85 | WEBCORE_EXPORT bool isStatusCodePotentiallyCacheable(int statusCode); |
86 | |
87 | } |
88 | |