Changeset 203221 in webkit


Ignore:
Timestamp:
Jul 14, 2016 3:14:53 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[Fetch API] Request and Response url getter should use URL serialization
https://bugs.webkit.org/show_bug.cgi?id=159705

Patch by Youenn Fablet <youenn@apple.com> on 2016-07-14
Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

  • web-platform-tests/fetch/api/basic/response-url-expected.txt: Added.
  • web-platform-tests/fetch/api/basic/response-url-worker-expected.txt: Added.
  • web-platform-tests/fetch/api/basic/response-url-worker.html: Added.
  • web-platform-tests/fetch/api/basic/response-url.html: Added.
  • web-platform-tests/fetch/api/basic/response-url.js: Added.

(checkResponseURL):

  • web-platform-tests/fetch/api/request/request-init-003.sub-expected.txt:
  • web-platform-tests/fetch/api/request/request-init-003.sub.html:

Source/WebCore:

Tests: fetch/fetch-url-serialization.html

imported/w3c/web-platform-tests/fetch/api/basic/response-url-worker.html
imported/w3c/web-platform-tests/fetch/api/basic/response-url.html

Implementing https://url.spec.whatwg.org/#concept-url-serializer and applying it to Request and Response getter.
Adding a temporary routine to compute url cannot-be-a-base-url flag. The parsing routine should store that
information in the URL itself.

Added tests to cover serialization routine. Failing tests are mostly due to limitations of the URL parser.
Tests do not check for URLs with username and password as Request constructor throws with such URLs.

  • Modules/fetch/FetchRequest.cpp:

(WebCore::FetchRequest::url): Adding request url serialization, fragment included.

  • Modules/fetch/FetchRequest.h:
  • Modules/fetch/FetchResponse.cpp:

(WebCore::FetchResponse::url): Adding response url serialization, fragment excluded.

  • Modules/fetch/FetchResponse.h:
  • platform/URL.cpp:

(WebCore::cannotBeABaseURL): Temporary helper function to have a coarse evaluation of url cannot-be-a-base-url flag.
(WebCore::URL::serialize): Implementation of https://url.spec.whatwg.org/#concept-url-serializer.

  • platform/URL.h:

(WebCore::URL::hasUser): Helper getter.
(WebCore::URL::hasPassword): Ditto.
(WebCore::URL::hasQuery): Ditto.
(WebCore::URL::hasFragment): Ditto.

LayoutTests:

  • fetch/fetch-url-serialization-expected.txt: Added.
  • fetch/fetch-url-serialization.html: Added.
  • fetch/fetch-urls.json: Added.
Location:
trunk
Files:
3 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r203219 r203221  
     12016-07-14  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Request and Response url getter should use URL serialization
     4        https://bugs.webkit.org/show_bug.cgi?id=159705
     5
     6        Reviewed by Alex Christensen.
     7
     8        * fetch/fetch-url-serialization-expected.txt: Added.
     9        * fetch/fetch-url-serialization.html: Added.
     10        * fetch/fetch-urls.json: Added.
     11
    1122016-07-14  Jer Noble  <jer.noble@apple.com>
    213
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r203201 r203221  
     12016-07-14  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Request and Response url getter should use URL serialization
     4        https://bugs.webkit.org/show_bug.cgi?id=159705
     5
     6        Reviewed by Alex Christensen.
     7
     8        * web-platform-tests/fetch/api/basic/response-url-expected.txt: Added.
     9        * web-platform-tests/fetch/api/basic/response-url-worker-expected.txt: Added.
     10        * web-platform-tests/fetch/api/basic/response-url-worker.html: Added.
     11        * web-platform-tests/fetch/api/basic/response-url.html: Added.
     12        * web-platform-tests/fetch/api/basic/response-url.js: Added.
     13        (checkResponseURL):
     14        * web-platform-tests/fetch/api/request/request-init-003.sub-expected.txt:
     15        * web-platform-tests/fetch/api/request/request-init-003.sub.html:
     16
    1172016-07-13  Jiewen Tan  <jiewen_tan@apple.com>
    218
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/response-url-expected.txt

    r203164 r203221  
    11
    22PASS Testing response url getter with http://localhost:8800/ada
    3 FAIL Testing response url getter with http://localhost:8800/# assert_equals: expected "http://localhost:8800/" but got "http://localhost:8800/#"
    4 FAIL Testing response url getter with http://localhost:8800/#ada assert_equals: expected "http://localhost:8800/" but got "http://localhost:8800/#ada"
    5 FAIL Testing response url getter with http://localhost:8800#ada assert_equals: expected "http://localhost:8800/" but got "http://localhost:8800/#ada"
     3PASS Testing response url getter with http://localhost:8800/#
     4PASS Testing response url getter with http://localhost:8800/#ada
     5PASS Testing response url getter with http://localhost:8800#ada
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/response-url-worker-expected.txt

    r203164 r203221  
    11
    22PASS Testing response url getter with http://localhost:8800/ada
    3 FAIL Testing response url getter with http://localhost:8800/# assert_equals: expected "http://localhost:8800/" but got "http://localhost:8800/#"
    4 FAIL Testing response url getter with http://localhost:8800/#ada assert_equals: expected "http://localhost:8800/" but got "http://localhost:8800/#ada"
    5 FAIL Testing response url getter with http://localhost:8800#ada assert_equals: expected "http://localhost:8800/" but got "http://localhost:8800/#ada"
     3PASS Testing response url getter with http://localhost:8800/#
     4PASS Testing response url getter with http://localhost:8800/#ada
     5PASS Testing response url getter with http://localhost:8800#ada
    66
  • trunk/Source/WebCore/ChangeLog

    r203220 r203221  
     12016-07-14  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Request and Response url getter should use URL serialization
     4        https://bugs.webkit.org/show_bug.cgi?id=159705
     5
     6        Reviewed by Alex Christensen.
     7
     8        Tests: fetch/fetch-url-serialization.html
     9               imported/w3c/web-platform-tests/fetch/api/basic/response-url-worker.html
     10               imported/w3c/web-platform-tests/fetch/api/basic/response-url.html
     11
     12        Implementing https://url.spec.whatwg.org/#concept-url-serializer and applying it to Request and Response getter.
     13        Adding a temporary routine to compute url cannot-be-a-base-url flag. The parsing routine should store that
     14        information in the URL itself.
     15
     16        Added tests to cover serialization routine. Failing tests are mostly due to limitations of the URL parser.
     17        Tests do not check for URLs with username and password as Request constructor throws with such URLs.
     18
     19        * Modules/fetch/FetchRequest.cpp:
     20        (WebCore::FetchRequest::url): Adding request url serialization, fragment included.
     21        * Modules/fetch/FetchRequest.h:
     22        * Modules/fetch/FetchResponse.cpp:
     23        (WebCore::FetchResponse::url): Adding response url serialization, fragment excluded.
     24        * Modules/fetch/FetchResponse.h:
     25        * platform/URL.cpp:
     26        (WebCore::cannotBeABaseURL): Temporary helper function to have a coarse evaluation of url cannot-be-a-base-url flag.
     27        (WebCore::URL::serialize): Implementation of https://url.spec.whatwg.org/#concept-url-serializer.
     28        * platform/URL.h:
     29        (WebCore::URL::hasUser): Helper getter.
     30        (WebCore::URL::hasPassword): Ditto.
     31        (WebCore::URL::hasQuery): Ditto.
     32        (WebCore::URL::hasFragment): Ditto.
     33
    1342016-07-14  Sergio Villar Senin  <svillar@igalia.com>
    235
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp

    r202323 r203221  
    311311}
    312312
     313const String& FetchRequest::url() const
     314{
     315    if (m_requestURL.isNull())
     316        m_requestURL = m_internalRequest.request.url().serialize();
     317    return m_requestURL;
     318}
     319
    313320ResourceRequest FetchRequest::internalRequest() const
    314321{
  • trunk/Source/WebCore/Modules/fetch/FetchRequest.h

    r200361 r203221  
    5050
    5151    const String& method() const { return m_internalRequest.request.httpMethod(); }
    52     const String& url() const { return m_internalRequest.request.url().string(); }
     52    const String& url() const;
    5353    FetchHeaders& headers() { return m_headers.get(); }
    5454
     
    9999    Ref<FetchHeaders> m_headers;
    100100    InternalRequest m_internalRequest;
     101    mutable String m_requestURL;
    101102};
    102103
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp

    r203162 r203221  
    152152}
    153153
     154const String& FetchResponse::url() const
     155{
     156    if (m_responseURL.isNull())
     157        m_responseURL = m_response.url().serialize(true);
     158    return m_responseURL;
     159}
     160
    154161void FetchResponse::fetch(ScriptExecutionContext& context, const String& url, const Dictionary& dictionary, FetchPromise&& promise)
    155162{
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.h

    r203162 r203221  
    6262
    6363    Type type() const { return m_response.type(); }
    64     const String& url() const { return m_response.url().string(); }
     64    const String& url() const;
    6565    bool redirected() const { return m_response.isRedirected(); }
    6666    int status() const { return m_response.httpStatusCode(); }
     
    114114    Ref<FetchHeaders> m_headers;
    115115    Optional<BodyLoader> m_bodyLoader;
     116    mutable String m_responseURL;
    116117};
    117118
  • trunk/Source/WebCore/platform/URL.cpp

    r203013 r203221  
    11941194}
    11951195
     1196static inline bool cannotBeABaseURL(const URL& url)
     1197{
     1198    // FIXME: Support https://url.spec.whatwg.org/#url-cannot-be-a-base-url-flag properly
     1199    // According spec, this should be computed at parsing time.
     1200    // For the moment, we just check whether the scheme is special or not.
     1201    if (url.protocolIs("ftp") || url.protocolIs("file") || url.protocolIs("gopher") || url.protocolIs("http") || url.protocolIs("https") || url.protocolIs("ws") || url.protocolIs("wss"))
     1202        return false;
     1203    return true;
     1204}
     1205
     1206// Implementation of https://url.spec.whatwg.org/#url-serializing
     1207String URL::serialize(bool omitFragment) const
     1208{
     1209    if (isNull())
     1210        return String();
     1211
     1212    StringBuilder urlBuilder;
     1213    urlBuilder.append(m_string, 0, m_schemeEnd);
     1214    urlBuilder.append(":");
     1215    int start = hostStart();
     1216    if (start < m_hostEnd) {
     1217        urlBuilder.append("//");
     1218        if (hasUsername()) {
     1219            urlBuilder.append(m_string, m_userStart, m_userEnd - m_userStart);
     1220            int passwordStart = m_userEnd + 1;
     1221            if (hasPassword()) {
     1222                urlBuilder.append(":");
     1223                urlBuilder.append(m_string, passwordStart, m_passwordEnd - passwordStart);
     1224            }
     1225            urlBuilder.append("@");
     1226        }
     1227        // FIXME: Serialize host according https://url.spec.whatwg.org/#concept-host-serializer for IPv4 and IPv6 addresses.
     1228        urlBuilder.append(m_string, start, m_hostEnd - start);
     1229        if (hasPort()) {
     1230            urlBuilder.append(":");
     1231            urlBuilder.appendNumber(port());
     1232        }
     1233    } else if (protocolIs("file"))
     1234        urlBuilder.append("//");
     1235    if (cannotBeABaseURL(*this))
     1236        urlBuilder.append(m_string, m_portEnd, m_pathEnd - m_portEnd);
     1237    else {
     1238        urlBuilder.append("/");
     1239        if (m_pathEnd > m_portEnd) {
     1240            int pathStart = m_portEnd + 1;
     1241            urlBuilder.append(m_string, pathStart, m_pathEnd - pathStart);
     1242        }
     1243    }
     1244    if (hasQuery()) {
     1245        urlBuilder.append("?");
     1246        urlBuilder.append(m_string, m_pathEnd + 1, m_queryEnd - (m_pathEnd + 1));
     1247    }
     1248    if (!omitFragment && hasFragment()) {
     1249        urlBuilder.append("#");
     1250        urlBuilder.append(m_string, m_queryEnd + 1, m_fragmentEnd - (m_queryEnd + 1));
     1251    }
     1252    return urlBuilder.toString();
     1253}
     1254
    11961255#if PLATFORM(IOS)
    11971256static bool shouldCanonicalizeScheme = true;
  • trunk/Source/WebCore/platform/URL.h

    r203013 r203221  
    115115    WEBCORE_EXPORT bool hasFragmentIdentifier() const;
    116116
     117    bool hasUsername() const;
     118    bool hasPassword() const;
     119    bool hasQuery() const;
     120    bool hasFragment() const;
     121
    117122    // Unlike user() and pass(), these functions don't decode escape sequences.
    118123    // This is necessary for accurate round-tripping, because encoding doesn't encode '%' characters.
     
    198203    template <class Encoder> void encode(Encoder&) const;
    199204    template <class Decoder> static bool decode(Decoder&, URL&);
     205
     206    String serialize(bool omitFragment = false) const;
    200207
    201208private:
     
    391398}
    392399
     400inline bool URL::hasUsername() const
     401{
     402    return m_userEnd > m_userStart;
     403}
     404
     405inline bool URL::hasPassword() const
     406{
     407    return m_passwordEnd > (m_userEnd + 1);
     408}
     409
     410inline bool URL::hasQuery() const
     411{
     412    return m_queryEnd > m_pathEnd;
     413}
     414
     415inline bool URL::hasFragment() const
     416{
     417    return m_fragmentEnd > m_queryEnd;
     418}
     419
    393420inline bool URL::protocolIsInHTTPFamily() const
    394421{
Note: See TracChangeset for help on using the changeset viewer.