Changeset 181651 in webkit


Ignore:
Timestamp:
Mar 17, 2015 9:09:06 AM (9 years ago)
Author:
Antti Koivisto
Message:

Disk cache should support Vary: Cookie
https://bugs.webkit.org/show_bug.cgi?id=142770
Source/WebKit2:

rdar://problem/19764945

Reviewed by Anders Carlsson.

Cookies are not part of the original request but are added by the networking layer when submitting the request.
Fetch them explicitly when resolving Vary: Cookie.

The implementation is not perfect as it fetches the cookie for the cache entry when saving a Vary:Cookie response,
not when making the request. In principle the cookie may have changed in-between. This should be enough to handle
reasonable cases though. Fetching cookies for every request might be too expensive for this rarely used feature.

  • NetworkProcess/cache/NetworkCache.cpp:

(WebKit::NetworkCache::headerValueForVary):
(WebKit::NetworkCache::encodeStorageEntry):
(WebKit::NetworkCache::verifyVaryingRequestHeaders):

LayoutTests:

Reviewed by Anders Carlsson.

  • http/tests/cache/disk-cache-vary-cookie-expected.txt: Added.
  • http/tests/cache/disk-cache-vary-cookie.html: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r181618 r181651  
     12015-03-17  Antti Koivisto  <antti@apple.com>
     2
     3        Disk cache should support Vary: Cookie
     4        https://bugs.webkit.org/show_bug.cgi?id=142770
     5
     6        Reviewed by Anders Carlsson.
     7
     8        * http/tests/cache/disk-cache-vary-cookie-expected.txt: Added.
     9        * http/tests/cache/disk-cache-vary-cookie.html: Added.
     10
    1112015-03-16  Ryosuke Niwa  <rniwa@webkit.org>
    212
  • trunk/LayoutTests/platform/mac-wk1/TestExpectations

    r180771 r181651  
    9595http/tests/cache/disk-cache-validation.html
    9696http/tests/cache/disk-cache-disable.html
     97http/tests/cache/disk-cache-vary-cookie.html
    9798
    9899### END OF (2) Failures without bug reports
  • trunk/LayoutTests/platform/win/TestExpectations

    r181602 r181651  
    22232223http/tests/cache/disk-cache-validation.html
    22242224http/tests/cache/disk-cache-disable.html
     2225http/tests/cache/disk-cache-vary-cookie.html
    22252226
    22262227# The following are unreviewed:
  • trunk/Source/WebKit2/ChangeLog

    r181630 r181651  
     12015-03-17  Antti Koivisto  <antti@apple.com>
     2
     3        Disk cache should support Vary: Cookie
     4        https://bugs.webkit.org/show_bug.cgi?id=142770
     5        rdar://problem/19764945
     6
     7        Reviewed by Anders Carlsson.
     8
     9        Cookies are not part of the original request but are added by the networking layer when submitting the request.
     10        Fetch them explicitly when resolving Vary: Cookie.
     11
     12        The implementation is not perfect as it fetches the cookie for the cache entry when saving a Vary:Cookie response,
     13        not when making the request. In principle the cookie may have changed in-between. This should be enough to handle
     14        reasonable cases though. Fetching cookies for every request might be too expensive for this rarely used feature.
     15
     16        * NetworkProcess/cache/NetworkCache.cpp:
     17        (WebKit::NetworkCache::headerValueForVary):
     18        (WebKit::NetworkCache::encodeStorageEntry):
     19        (WebKit::NetworkCache::verifyVaryingRequestHeaders):
     20
    1212015-03-17  Zan Dobersek  <zdobersek@igalia.com>
    222
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCache.cpp

    r181364 r181651  
    3939#include <WebCore/FileSystem.h>
    4040#include <WebCore/HTTPHeaderNames.h>
     41#include <WebCore/NetworkStorageSession.h>
     42#include <WebCore/PlatformCookieJar.h>
    4143#include <WebCore/ResourceResponse.h>
    4244#include <WebCore/SharedBuffer.h>
     
    98100}
    99101
     102static String headerValueForVary(const WebCore::ResourceRequest& request, const String& headerName)
     103{
     104    // Explicit handling for cookies is needed because they are added magically by the networking layer.
     105    // FIXME: The value might have changed between making the request and retrieving the cookie here.
     106    // We could fetch the cookie when making the request but that seems overkill as the case is very rare and it
     107    // is a blocking operation. This should be sufficient to cover reasonable cases.
     108    if (headerName == httpHeaderNameString(WebCore::HTTPHeaderName::Cookie))
     109        return WebCore::cookieRequestHeaderFieldValue(WebCore::NetworkStorageSession::defaultStorageSession(), request.firstPartyForCookies(), request.url());
     110    return request.httpHeaderField(headerName);
     111}
     112
    100113static Storage::Entry encodeStorageEntry(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response, PassRefPtr<WebCore::SharedBuffer> responseData)
    101114{
     
    115128        for (auto& varyHeaderName : varyingHeaderNames) {
    116129            String headerName = varyHeaderName.stripWhiteSpace();
    117             varyingRequestHeaders.append(std::make_pair(headerName, request.httpHeaderField(headerName)));
     130            String headerValue = headerValueForVary(request, headerName);
     131            varyingRequestHeaders.append(std::make_pair(headerName, headerValue));
    118132        }
    119133        encoder << varyingRequestHeaders;
     
    136150        if (varyingRequestHeader.first == "*")
    137151            return false;
    138         String requestValue = request.httpHeaderField(varyingRequestHeader.first);
    139         if (requestValue != varyingRequestHeader.second)
     152        String headerValue = headerValueForVary(request, varyingRequestHeader.first);
     153        if (headerValue != varyingRequestHeader.second)
    140154            return false;
    141155    }
Note: See TracChangeset for help on using the changeset viewer.