Changeset 201324 in webkit


Ignore:
Timestamp:
May 24, 2016 12:35:09 AM (8 years ago)
Author:
youenn.fablet@crf.canon.fr
Message:

[Fetch API] Implement Fetch redirect mode
https://bugs.webkit.org/show_bug.cgi?id=157837

Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

  • web-platform-tests/fetch/api/redirect/redirect-location-expected.txt:
  • web-platform-tests/fetch/api/redirect/redirect-location.js:
  • web-platform-tests/fetch/api/redirect/redirect-method.js:
  • web-platform-tests/fetch/api/redirect/redirect-method-expected.txt:
  • web-platform-tests/fetch/api/redirect/redirect-mode-expected.txt:

Source/WebCore:

Implementing step 5 of https://fetch.spec.whatwg.org/#http-fetch.
Making ResourceLoaderOptions include FetchOptions.
This allows SubresourceLoader to follow or not redirections based on that option.
CachedResource is made responsible to handle the type of the response (opaqueredirect, opaque, cors, basic...).
If redirection is not to be followed, either an error is returned or an empty response is returned.

Moved Response type and redirected flag from FetchResponse to ResourceResponse.
This allows CachedResource to easily communicate that information to FetchResponse.

Made some clean-up refactoring in ThreadableLoaderOptions.

http/tests/fetch/caching-with-different-options.html ensures that
caching at CachedResourceLoader will not have bad effects on fetch.
Covered by updated and rebased tests.

  • Modules/fetch/FetchLoader.cpp:

(WebCore::FetchLoader::start):

  • Modules/fetch/FetchResponse.cpp:

(WebCore::FetchResponse::error):
(WebCore::FetchResponse::redirect):
(WebCore::FetchResponse::FetchResponse):
(WebCore::FetchResponse::clone):
(WebCore::FetchResponse::startFetching):

  • Modules/fetch/FetchResponse.h:
  • WebCore.xcodeproj/project.pbxproj:
  • loader/FetchOptions.h: Moved from Source/WebCore/Modules/fetch/FetchOptions.h.
  • loader/ResourceLoaderOptions.h:

(WebCore::ResourceLoaderOptions::fetchOptions):
(WebCore::ResourceLoaderOptions::setFetchOptions):

  • loader/SubresourceLoader.cpp:

(WebCore::SubresourceLoader::willSendRequestInternal):

  • loader/ThreadableLoader.cpp:
  • loader/ThreadableLoader.h:
  • loader/cache/CachedResource.cpp:

(WebCore::CachedResource::setResponse):

  • loader/cache/CachedResource.h:

(WebCore::CachedResource::setOpaqueRedirect):

  • platform/network/ResourceResponseBase.cpp:

(WebCore::ResourceResponseBase::adopt):
(WebCore::ResourceResponseBase::copyData):

  • platform/network/ResourceResponseBase.h:

(WebCore::ResourceResponseBase::type):
(WebCore::ResourceResponseBase::setType):
(WebCore::ResourceResponseBase::encode):
(WebCore::ResourceResponseBase::decode):

LayoutTests:

  • http/tests/fetch/caching-with-different-options-expected.txt: Added.
  • http/tests/fetch/caching-with-different-options.html: Added.
  • http/tests/fetch/resources/redirect-with-cache.php: Added.
  • platform/gtk/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location-expected.txt:
  • platform/gtk/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-method-expected.txt:
Location:
trunk
Files:
4 added
22 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r201323 r201324  
     12016-05-24  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        [Fetch API] Implement Fetch redirect mode
     4        https://bugs.webkit.org/show_bug.cgi?id=157837
     5
     6        Reviewed by Alex Christensen.
     7
     8        * http/tests/fetch/caching-with-different-options-expected.txt: Added.
     9        * http/tests/fetch/caching-with-different-options.html: Added.
     10        * http/tests/fetch/resources/redirect-with-cache.php: Added.
     11        * platform/gtk/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location-expected.txt:
     12        * platform/gtk/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-method-expected.txt:
     13
    1142016-05-23  Yoav Weiss  <yoav@yoav.ws>
    215
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r201073 r201324  
     12016-05-24  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        [Fetch API] Implement Fetch redirect mode
     4        https://bugs.webkit.org/show_bug.cgi?id=157837
     5
     6        Reviewed by Alex Christensen.
     7
     8        * web-platform-tests/fetch/api/redirect/redirect-location-expected.txt:
     9        * web-platform-tests/fetch/api/redirect/redirect-location.js:
     10        * web-platform-tests/fetch/api/redirect/redirect-method.js:
     11        * web-platform-tests/fetch/api/redirect/redirect-method-expected.txt:
     12        * web-platform-tests/fetch/api/redirect/redirect-mode-expected.txt:
     13
    1142016-05-18  Antti Koivisto  <antti@apple.com>
    215
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location-expected.txt

    r200195 r201324  
    55PASS Redirect 301 in "manual" mode with invalid location
    66PASS Redirect 301 in "follow" mode with data location
    7 FAIL Redirect 301 in "manual" mode with data location promise_test: Unhandled rejection with value: object "TypeError: Type error"
     7PASS Redirect 301 in "manual" mode with data location
    88PASS Redirect 302 in "follow" mode without location
    99PASS Redirect 302 in "manual" mode without location
     
    1111PASS Redirect 302 in "manual" mode with invalid location
    1212PASS Redirect 302 in "follow" mode with data location
    13 FAIL Redirect 302 in "manual" mode with data location promise_test: Unhandled rejection with value: object "TypeError: Type error"
     13PASS Redirect 302 in "manual" mode with data location
    1414PASS Redirect 303 in "follow" mode without location
    1515PASS Redirect 303 in "manual" mode without location
     
    1717PASS Redirect 303 in "manual" mode with invalid location
    1818PASS Redirect 303 in "follow" mode with data location
    19 FAIL Redirect 303 in "manual" mode with data location promise_test: Unhandled rejection with value: object "TypeError: Type error"
     19PASS Redirect 303 in "manual" mode with data location
    2020PASS Redirect 307 in "follow" mode without location
    2121PASS Redirect 307 in "manual" mode without location
     
    2323PASS Redirect 307 in "manual" mode with invalid location
    2424PASS Redirect 307 in "follow" mode with data location
    25 FAIL Redirect 307 in "manual" mode with data location promise_test: Unhandled rejection with value: object "TypeError: Type error"
     25PASS Redirect 307 in "manual" mode with data location
    2626PASS Redirect 308 in "follow" mode without location
    2727PASS Redirect 308 in "manual" mode without location
     
    2929PASS Redirect 308 in "manual" mode with invalid location
    3030PASS Redirect 308 in "follow" mode with data location
    31 FAIL Redirect 308 in "manual" mode with data location promise_test: Unhandled rejection with value: object "TypeError: Type error"
     31PASS Redirect 308 in "manual" mode with data location
    3232
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location.js

    r200195 r201324  
    4242
    4343  redirectLocation("Redirect " + statusCode + " in \"follow\" mode with invalid location", redirUrl, invalidLocationUrl, statusCode, "follow", false);
    44   redirectLocation("Redirect " + statusCode + " in \"manual\" mode with invalid location", redirUrl, invalidLocationUrl, statusCode, "manual", false);
     44  redirectLocation("Redirect " + statusCode + " in \"manual\" mode with invalid location", redirUrl, invalidLocationUrl, statusCode, "manual", true);
    4545
    4646  redirectLocation("Redirect " + statusCode + " in \"follow\" mode with data location", redirUrl, dataLocationUrl, statusCode, "follow", false);
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-method-expected.txt

    r200195 r201324  
    11
     2PASS Response.redirected should be false on not-redirected responses
    23PASS Redirect 301 with GET
    34PASS Redirect 301 with POST
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-method.js

    r200195 r201324  
    1818      assert_equals(resp.type, "basic", "Response's type basic");
    1919      assert_equals(resp.headers.get("x-request-method"), expectedMethod, "Request method after redirection is " + expectedMethod);
     20      assert_true(resp.redirected);
    2021      return resp.text().then(function(text) {
    2122        assert_equals(text, expectedMethod == "POST" ? requestInit.body : "");
     
    2425  }, desc);
    2526}
     27
     28promise_test(function(test) {
     29    assert_false(new Response().redirected);
     30    return fetch(RESOURCES_DIR + "method.py").then(function(resp) {
     31      assert_equals(resp.status, 200, "Response's status is 200");
     32      assert_false(resp.redirected);
     33    });
     34}, "Response.redirected should be false on not-redirected responses");
    2635
    2736var redirUrl = RESOURCES_DIR + "redirect.py";
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-mode-expected.txt

    r200195 r201324  
    11
    2 FAIL Redirect 301 in "error" mode  assert_unreached: Should have rejected. Reached unreachable code
     2PASS Redirect 301 in "error" mode 
    33PASS Redirect 301 in "follow" mode 
    4 FAIL Redirect 301 in "manual" mode  assert_equals: Response's status is 0 expected 0 but got 200
    5 FAIL Redirect 302 in "error" mode  assert_unreached: Should have rejected. Reached unreachable code
     4PASS Redirect 301 in "manual" mode 
     5PASS Redirect 302 in "error" mode 
    66PASS Redirect 302 in "follow" mode 
    7 FAIL Redirect 302 in "manual" mode  assert_equals: Response's status is 0 expected 0 but got 200
    8 FAIL Redirect 303 in "error" mode  assert_unreached: Should have rejected. Reached unreachable code
     7PASS Redirect 302 in "manual" mode 
     8PASS Redirect 303 in "error" mode 
    99PASS Redirect 303 in "follow" mode 
    10 FAIL Redirect 303 in "manual" mode  assert_equals: Response's status is 0 expected 0 but got 200
    11 FAIL Redirect 307 in "error" mode  assert_unreached: Should have rejected. Reached unreachable code
     10PASS Redirect 303 in "manual" mode 
     11PASS Redirect 307 in "error" mode 
    1212PASS Redirect 307 in "follow" mode 
    13 FAIL Redirect 307 in "manual" mode  assert_equals: Response's status is 0 expected 0 but got 200
    14 FAIL Redirect 308 in "error" mode  assert_unreached: Should have rejected. Reached unreachable code
     13PASS Redirect 307 in "manual" mode 
     14PASS Redirect 308 in "error" mode 
    1515PASS Redirect 308 in "follow" mode 
    16 FAIL Redirect 308 in "manual" mode  assert_equals: Response's status is 0 expected 0 but got 200
     16PASS Redirect 308 in "manual" mode 
    1717
  • trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-location-expected.txt

    r200195 r201324  
    77PASS Redirect 301 in "manual" mode with invalid location
    88PASS Redirect 301 in "follow" mode with data location
    9 FAIL Redirect 301 in "manual" mode with data location promise_test: Unhandled rejection with value: object "TypeError: Type error"
     9PASS Redirect 301 in "manual" mode with data location
    1010PASS Redirect 302 in "follow" mode without location
    1111PASS Redirect 302 in "manual" mode without location
     
    1313PASS Redirect 302 in "manual" mode with invalid location
    1414PASS Redirect 302 in "follow" mode with data location
    15 FAIL Redirect 302 in "manual" mode with data location promise_test: Unhandled rejection with value: object "TypeError: Type error"
     15PASS Redirect 302 in "manual" mode with data location
    1616PASS Redirect 303 in "follow" mode without location
    1717PASS Redirect 303 in "manual" mode without location
    1818PASS Redirect 303 in "follow" mode with invalid location
    19 TIMEOUT Redirect 303 in "manual" mode with invalid location Test timed out
    20 TIMEOUT Redirect 303 in "follow" mode with data location Test timed out
    21 TIMEOUT Redirect 303 in "manual" mode with data location Test timed out
    22 TIMEOUT Redirect 307 in "follow" mode without location Test timed out
    23 TIMEOUT Redirect 307 in "manual" mode without location Test timed out
    24 TIMEOUT Redirect 307 in "follow" mode with invalid location Test timed out
    25 TIMEOUT Redirect 307 in "manual" mode with invalid location Test timed out
    26 TIMEOUT Redirect 307 in "follow" mode with data location Test timed out
    27 TIMEOUT Redirect 307 in "manual" mode with data location Test timed out
    28 TIMEOUT Redirect 308 in "follow" mode without location Test timed out
    29 TIMEOUT Redirect 308 in "manual" mode without location Test timed out
     19PASS Redirect 303 in "manual" mode with invalid location
     20PASS Redirect 303 in "follow" mode with data location
     21PASS Redirect 303 in "manual" mode with data location
     22PASS Redirect 307 in "follow" mode without location
     23PASS Redirect 307 in "manual" mode without location
     24PASS Redirect 307 in "follow" mode with invalid location
     25PASS Redirect 307 in "manual" mode with invalid location
     26PASS Redirect 307 in "follow" mode with data location
     27PASS Redirect 307 in "manual" mode with data location
     28PASS Redirect 308 in "follow" mode without location
     29PASS Redirect 308 in "manual" mode without location
    3030TIMEOUT Redirect 308 in "follow" mode with invalid location Test timed out
    3131TIMEOUT Redirect 308 in "manual" mode with invalid location Test timed out
  • trunk/LayoutTests/platform/gtk/imported/w3c/web-platform-tests/fetch/api/redirect/redirect-method-expected.txt

    r200195 r201324  
    11
     2PASS Response.redirected should be false on not-redirected responses
    23PASS Redirect 301 with GET
    34PASS Redirect 301 with POST
  • trunk/Source/WebCore/ChangeLog

    r201322 r201324  
     12016-05-24  Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        [Fetch API] Implement Fetch redirect mode
     4        https://bugs.webkit.org/show_bug.cgi?id=157837
     5
     6        Reviewed by Alex Christensen.
     7
     8        Implementing step 5 of https://fetch.spec.whatwg.org/#http-fetch.
     9        Making ResourceLoaderOptions include FetchOptions.
     10        This allows SubresourceLoader to follow or not redirections based on that option.
     11        CachedResource is made responsible to handle the type of the response (opaqueredirect, opaque, cors, basic...).
     12        If redirection is not to be followed, either an error is returned or an empty response is returned.
     13
     14        Moved Response type and redirected flag from FetchResponse to ResourceResponse.
     15        This allows CachedResource to easily communicate that information to FetchResponse.
     16
     17        Made some clean-up refactoring in ThreadableLoaderOptions.
     18
     19        http/tests/fetch/caching-with-different-options.html ensures that
     20        caching at CachedResourceLoader will not have bad effects on fetch.
     21        Covered by updated and rebased tests.
     22
     23        * Modules/fetch/FetchLoader.cpp:
     24        (WebCore::FetchLoader::start):
     25        * Modules/fetch/FetchResponse.cpp:
     26        (WebCore::FetchResponse::error):
     27        (WebCore::FetchResponse::redirect):
     28        (WebCore::FetchResponse::FetchResponse):
     29        (WebCore::FetchResponse::clone):
     30        (WebCore::FetchResponse::startFetching):
     31        * Modules/fetch/FetchResponse.h:
     32        * WebCore.xcodeproj/project.pbxproj:
     33        * loader/FetchOptions.h: Moved from Source/WebCore/Modules/fetch/FetchOptions.h.
     34        * loader/ResourceLoaderOptions.h:
     35        (WebCore::ResourceLoaderOptions::fetchOptions):
     36        (WebCore::ResourceLoaderOptions::setFetchOptions):
     37        * loader/SubresourceLoader.cpp:
     38        (WebCore::SubresourceLoader::willSendRequestInternal):
     39        * loader/ThreadableLoader.cpp:
     40        * loader/ThreadableLoader.h:
     41        * loader/cache/CachedResource.cpp:
     42        (WebCore::CachedResource::setResponse):
     43        * loader/cache/CachedResource.h:
     44        (WebCore::CachedResource::setOpaqueRedirect):
     45        * platform/network/ResourceResponseBase.cpp:
     46        (WebCore::ResourceResponseBase::adopt):
     47        (WebCore::ResourceResponseBase::copyData):
     48        * platform/network/ResourceResponseBase.h:
     49        (WebCore::ResourceResponseBase::type):
     50        (WebCore::ResourceResponseBase::setType):
     51        (WebCore::ResourceResponseBase::encode):
     52        (WebCore::ResourceResponseBase::decode):
     53
    1542016-05-23  Yusuke Suzuki  <utatane.tea@gmail.com>
    255
  • trunk/Source/WebCore/Modules/fetch/FetchLoader.cpp

    r199641 r201324  
    6969
    7070    m_loader = ThreadableLoader::create(&context, this, request, options);
    71     m_isStarted = true;
     71    m_isStarted = m_loader;
    7272}
    7373
     
    8383    options.crossOriginRequestPolicy = DenyCrossOriginRequests;
    8484    options.contentSecurityPolicyEnforcement = ContentSecurityPolicyEnforcement::DoNotEnforce;
     85    options.setFetchOptions(request.fetchOptions());
    8586
    8687    m_loader = ThreadableLoader::create(&context, this, request.internalRequest(), options);
    87     m_isStarted = true;
     88    m_isStarted = m_loader;
    8889}
    8990
     
    9798{
    9899    m_data = nullptr;
    99     if (m_loader) {
    100         RefPtr<ThreadableLoader> loader = WTFMove(m_loader);
    101         loader->cancel();
    102     }
     100    if (m_loader)
     101        m_loader->cancel();
    103102}
    104103
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp

    r201013 r201324  
    5252Ref<FetchResponse> FetchResponse::error(ScriptExecutionContext& context)
    5353{
    54     return adoptRef(*new FetchResponse(context, Type::Error, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
     54    auto response = adoptRef(*new FetchResponse(context, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
     55    response->m_response.setType(Type::Error);
     56    return response;
    5557}
    5658
     
    6769        return nullptr;
    6870    }
    69     auto redirectResponse = adoptRef(*new FetchResponse(context, Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
     71    auto redirectResponse = adoptRef(*new FetchResponse(context, { }, FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
    7072    redirectResponse->m_response.setHTTPStatusCode(status);
    7173    redirectResponse->m_headers->fastSet(HTTPHeaderName::Location, requestURL.string());
     
    110112}
    111113
    112 FetchResponse::FetchResponse(ScriptExecutionContext& context, Type type, FetchBody&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
     114FetchResponse::FetchResponse(ScriptExecutionContext& context, FetchBody&& body, Ref<FetchHeaders>&& headers, ResourceResponse&& response)
    113115    : FetchBodyOwner(context, WTFMove(body))
    114     , m_type(type)
    115116    , m_response(WTFMove(response))
    116117    , m_headers(WTFMove(headers))
     
    124125        return nullptr;
    125126    }
    126     auto cloned = adoptRef(*new FetchResponse(context, m_type, FetchBody(m_body), FetchHeaders::create(headers()), ResourceResponse(m_response)));
    127     cloned->m_isRedirected = m_isRedirected;
    128     return WTFMove(cloned);
     127    return adoptRef(*new FetchResponse(context, FetchBody(m_body), FetchHeaders::create(headers()), ResourceResponse(m_response)));
    129128}
    130129
    131130void FetchResponse::startFetching(ScriptExecutionContext& context, const FetchRequest& request, FetchPromise&& promise)
    132131{
    133     auto response = adoptRef(*new FetchResponse(context, Type::Basic, FetchBody::loadingBody(), FetchHeaders::create(FetchHeaders::Guard::Immutable), ResourceResponse()));
     132    auto response = adoptRef(*new FetchResponse(context, FetchBody::loadingBody(), FetchHeaders::create(FetchHeaders::Guard::Immutable), { }));
    134133
    135134    // Setting pending activity until BodyLoader didFail or didSucceed callback is called.
     
    174173    }
    175174#endif
    176     m_response.m_bodyLoader = Nullopt;
     175    if (m_loader->isStarted())
     176        m_response.m_bodyLoader = Nullopt;
    177177    m_response.unsetPendingActivity(&m_response);
    178178}
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.h

    r201013 r201324  
    4949class FetchResponse final : public FetchBodyOwner {
    5050public:
    51     enum class Type { Basic, Cors, Default, Error, Opaque, Opaqueredirect };
     51    using Type = ResourceResponse::Type;
    5252
    53     static Ref<FetchResponse> create(ScriptExecutionContext& context) { return adoptRef(*new FetchResponse(context, Type::Default, { }, FetchHeaders::create(FetchHeaders::Guard::Response), ResourceResponse())); }
     53    static Ref<FetchResponse> create(ScriptExecutionContext& context) { return adoptRef(*new FetchResponse(context, { }, FetchHeaders::create(FetchHeaders::Guard::Response), ResourceResponse())); }
    5454    static Ref<FetchResponse> error(ScriptExecutionContext&);
    5555    static RefPtr<FetchResponse> redirect(ScriptExecutionContext&, const String&, int, ExceptionCode&);
     
    6161    void initializeWith(const Dictionary&, ExceptionCode&);
    6262
    63     Type type() const;
     63    Type type() const { return m_response.type(); }
    6464    const String& url() const { return m_response.url().string(); }
    65     bool redirected() const { return m_isRedirected; }
     65    bool redirected() const { return m_response.isRedirected(); }
    6666    int status() const { return m_response.httpStatusCode(); }
    6767    bool ok() const { return status() >= 200 && status() <= 299; }
     
    7777
    7878private:
    79     FetchResponse(ScriptExecutionContext&, Type, FetchBody&&, Ref<FetchHeaders>&&, ResourceResponse&&);
     79    FetchResponse(ScriptExecutionContext&, FetchBody&&, Ref<FetchHeaders>&&, ResourceResponse&&);
    8080
    8181    static void startFetching(ScriptExecutionContext&, const FetchRequest&, FetchPromise&&);
     
    101101        void didSucceed() final;
    102102        void didFail() final;
    103         void didReceiveResponse(const ResourceResponse&);
     103        void didReceiveResponse(const ResourceResponse&) final;
    104104        void didReceiveData(const char*, size_t) final;
    105105        void didFinishLoadingAsArrayBuffer(RefPtr<ArrayBuffer>&&) final;
     
    110110    };
    111111
    112     Type m_type;
    113112    ResourceResponse m_response;
    114113    Ref<FetchHeaders> m_headers;
    115     bool m_isRedirected = false;
    116114    Optional<BodyLoader> m_bodyLoader;
    117115};
    118 
    119 inline auto FetchResponse::type() const -> Type
    120 {
    121     return m_type;
    122 }
    123116
    124117} // namespace WebCore
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r201290 r201324  
    15721572                41A3D58E101C152D00316D07 /* DedicatedWorkerThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41A3D58C101C152D00316D07 /* DedicatedWorkerThread.cpp */; };
    15731573                41A3D58F101C152D00316D07 /* DedicatedWorkerThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 41A3D58D101C152D00316D07 /* DedicatedWorkerThread.h */; };
     1574                41AD753A1CEF6BD100A31486 /* FetchOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 41AD75391CEF6BCE00A31486 /* FetchOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
    15741575                41BF700C0FE86F49005E8DEC /* MessagePortChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 41BF700A0FE86F49005E8DEC /* MessagePortChannel.h */; settings = {ATTRIBUTES = (Private, ); }; };
    15751576                41BF700F0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41BF700D0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp */; };
     
    90709071                41A3D58C101C152D00316D07 /* DedicatedWorkerThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DedicatedWorkerThread.cpp; sourceTree = "<group>"; };
    90719072                41A3D58D101C152D00316D07 /* DedicatedWorkerThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DedicatedWorkerThread.h; sourceTree = "<group>"; };
     9073                41AD75391CEF6BCE00A31486 /* FetchOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchOptions.h; sourceTree = "<group>"; };
    90729074                41BF700A0FE86F49005E8DEC /* MessagePortChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessagePortChannel.h; sourceTree = "<group>"; };
    90739075                41BF700D0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PlatformMessagePortChannel.cpp; path = default/PlatformMessagePortChannel.cpp; sourceTree = "<group>"; };
     
    90929094                41F54F841C50C4F600338488 /* FetchHeaders.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = FetchHeaders.idl; sourceTree = "<group>"; };
    90939095                41F54F851C50C4F600338488 /* FetchHeaders.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = FetchHeaders.js; sourceTree = "<group>"; };
    9094                 41F54F861C50C4F600338488 /* FetchOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchOptions.h; sourceTree = "<group>"; };
    90959096                41F54F871C50C4F600338488 /* FetchRequest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FetchRequest.cpp; sourceTree = "<group>"; };
    90969097                41F54F881C50C4F600338488 /* FetchRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchRequest.h; sourceTree = "<group>"; };
     
    1683816839                                4147E2B51C89912600A7E715 /* FetchLoader.h */,
    1683916840                                4147E2B61C89912600A7E715 /* FetchLoaderClient.h */,
    16840                                 41F54F861C50C4F600338488 /* FetchOptions.h */,
    1684116841                                41F54F871C50C4F600338488 /* FetchRequest.cpp */,
    1684216842                                41F54F881C50C4F600338488 /* FetchRequest.h */,
     
    2272722727                                F52AD5E31534245F0059FBE6 /* EmptyClients.cpp */,
    2272822728                                B255990D0D00D8B900BB825C /* EmptyClients.h */,
     22729                                41AD75391CEF6BCE00A31486 /* FetchOptions.h */,
    2272922730                                656D37230ADBA5DE00A4554D /* FormState.cpp */,
    2273022731                                656D37220ADBA5DE00A4554D /* FormState.h */,
     
    2824728248                                0880F70E1282B46D00948505 /* SVGStaticListPropertyTearOff.h in Headers */,
    2824828249                                0813A4EA1284132600992511 /* SVGStaticPropertyTearOff.h in Headers */,
     28250                                41AD753A1CEF6BD100A31486 /* FetchOptions.h in Headers */,
    2824928251                                B2227AA90D00BF220071B782 /* SVGStopElement.h in Headers */,
    2825028252                                B2227AAC0D00BF220071B782 /* SVGStringList.h in Headers */,
  • trunk/Source/WebCore/loader/FetchOptions.h

    r201323 r201324  
    2929#pragma once
    3030
    31 #if ENABLE(FETCH_API)
    32 
    3331namespace WebCore {
    3432
     
    5755
    5856} // namespace WebCore
    59 
    60 #endif // ENABLE(FETCH_API)
  • trunk/Source/WebCore/loader/ResourceLoaderOptions.h

    r195770 r201324  
    3232#define ResourceLoaderOptions_h
    3333
     34#include "FetchOptions.h"
    3435#include "ResourceHandleTypes.h"
    3536
     
    136137    CachingPolicy cachingPolicy() const { return m_cachingPolicy; }
    137138    void setCachingPolicy(CachingPolicy cachingPolicy) { m_cachingPolicy = cachingPolicy; }
     139    FetchOptions fetchOptions() const { return m_fetchOptions; }
     140    void setFetchOptions(FetchOptions fetchOptions) { m_fetchOptions = fetchOptions; }
    138141
    139142    unsigned m_sendLoadCallbacks : 1;
     
    149152    DefersLoadingPolicy m_defersLoadingPolicy { DefersLoadingPolicy::AllowDefersLoading };
    150153    CachingPolicy m_cachingPolicy { CachingPolicy::AllowCaching };
     154    FetchOptions m_fetchOptions;
    151155};
    152156
  • trunk/Source/WebCore/loader/SubresourceLoader.cpp

    r200895 r201324  
    176176    ASSERT(!newRequest.isNull());
    177177    if (!redirectResponse.isNull()) {
     178        if (options().fetchOptions().redirect != FetchOptions::Redirect::Follow) {
     179            if (options().fetchOptions().redirect == FetchOptions::Redirect::Error) {
     180                cancel();
     181                return;
     182            }
     183            m_resource->setOpaqueRedirect();
     184            m_resource->responseReceived({ });
     185            didFinishLoading(currentTime());
     186            return;
     187        }
     188
    178189        // CachedResources are keyed off their original request URL.
    179190        // Requesting the same original URL a second time can redirect to a unique second resource.
  • trunk/Source/WebCore/loader/ThreadableLoader.cpp

    r197551 r201324  
    4343
    4444ThreadableLoaderOptions::ThreadableLoaderOptions()
    45     : preflightPolicy(ConsiderPreflight)
    46     , crossOriginRequestPolicy(DenyCrossOriginRequests)
    4745{
    4846}
  • trunk/Source/WebCore/loader/ThreadableLoader.h

    r197551 r201324  
    7373        std::unique_ptr<ThreadableLoaderOptions> isolatedCopy() const;
    7474
    75         PreflightPolicy preflightPolicy; // If AccessControl is used, how to determine if a preflight is needed.
    76         CrossOriginRequestPolicy crossOriginRequestPolicy;
     75        PreflightPolicy preflightPolicy { ConsiderPreflight };
     76        CrossOriginRequestPolicy crossOriginRequestPolicy { DenyCrossOriginRequests };
    7777        ContentSecurityPolicyEnforcement contentSecurityPolicyEnforcement { ContentSecurityPolicyEnforcement::EnforceConnectSrcDirective };
    7878        RefPtr<SecurityOrigin> securityOrigin;
  • trunk/Source/WebCore/loader/cache/CachedResource.cpp

    r199650 r201324  
    412412}
    413413
     414void CachedResource::setResponse(const ResourceResponse& response)
     415{
     416    m_response = response;
     417    m_response.setType(m_responseType);
     418    m_response.setRedirected(m_redirectChainCacheStatus.status != RedirectChainCacheStatus::NoRedirection);
     419}
     420
    414421void CachedResource::responseReceived(const ResourceResponse& response)
    415422{
  • trunk/Source/WebCore/loader/cache/CachedResource.h

    r199881 r201324  
    200200    virtual void responseReceived(const ResourceResponse&);
    201201    virtual bool shouldCacheResponse(const ResourceResponse&) { return true; }
    202     void setResponse(const ResourceResponse& response) { m_response = response; }
     202    void setResponse(const ResourceResponse&);
     203    void setOpaqueRedirect() { m_responseType = ResourceResponseBase::Type::Opaqueredirect; }
    203204    const ResourceResponse& response() const { return m_response; }
    204205    // This is the same as response() except after HTTP redirect to data: URL.
     
    282283    ResourceLoaderOptions m_options;
    283284    ResourceResponse m_response;
     285    ResourceResponseBase::Type m_responseType { ResourceResponseBase::Type::Basic };
    284286    ResourceResponse m_redirectResponseForSameOriginPolicyChecks;
    285287    RefPtr<SharedBuffer> m_data;
  • trunk/Source/WebCore/platform/network/ResourceResponseBase.cpp

    r199590 r201324  
    7979    response->m_httpHeaderFields.adopt(WTFMove(data->m_httpHeaders));
    8080    response->m_resourceLoadTiming = data->m_resourceLoadTiming;
     81    response->m_type = data->m_type;
    8182    response->doPlatformAdopt(WTFMove(data));
    8283    return response;
     
    9596    data->m_httpHeaders = httpHeaderFields().copyData();
    9697    data->m_resourceLoadTiming = m_resourceLoadTiming;
     98    data->m_type = m_type;
    9799    return asResourceResponse().doPlatformCopyData(WTFMove(data));
    98100}
  • trunk/Source/WebCore/platform/network/ResourceResponseBase.h

    r200909 r201324  
    129129    }
    130130
     131    enum class Type { Basic, Cors, Default, Error, Opaque, Opaqueredirect };
     132    Type type() const { return m_type; }
     133    void setType(Type type) { m_type = type; }
     134    bool isRedirected() const { return m_isRedirected; }
     135    void setRedirected(bool isRedirected) { m_isRedirected = isRedirected; }
     136
    131137    static bool compare(const ResourceResponse&, const ResourceResponse&);
    132138
     
    190196
    191197    Source m_source { Source::Unknown };
     198
     199    Type m_type { Type::Default };
     200    bool m_isRedirected { false };
    192201};
    193202
     
    216225        encoder << m_certificateInfo;
    217226    encoder.encodeEnum(m_source);
     227    encoder.encodeEnum(m_type);
     228    encoder << m_isRedirected;
    218229}
    219230
     
    255266    }
    256267    if (!decoder.decodeEnum(response.m_source))
     268        return false;
     269    if (!decoder.decodeEnum(response.m_type))
     270        return false;
     271    if (!decoder.decode(response.m_isRedirected))
    257272        return false;
    258273    response.m_isNull = false;
     
    274289    std::unique_ptr<CrossThreadHTTPHeaderMapData> m_httpHeaders;
    275290    ResourceLoadTiming m_resourceLoadTiming;
     291    ResourceResponseBase::Type m_type;
     292    bool m_isRedirected;
    276293};
    277294
Note: See TracChangeset for help on using the changeset viewer.