Changeset 265014 in webkit


Ignore:
Timestamp:
Jul 28, 2020 3:24:43 PM (4 years ago)
Author:
Chris Dumez
Message:

[EventSource] WebKit fails to UTF-8 encode the Last-Event-ID HTTP header value
https://bugs.webkit.org/show_bug.cgi?id=214860

Reviewed by Alex Christensen and Darin Adler.

LayoutTests/imported/w3c:

Rebaseline a couple of web-platform-tests that are now passing.

  • web-platform-tests/eventsource/format-field-id-2-expected.txt:
  • web-platform-tests/eventsource/format-field-id-expected.txt:

Source/WebCore:

WebKit fails to UTF-8 encode the Last-Event-ID HTTP header value for EventSource.

The specification is here:
https://html.spec.whatwg.org/multipage/server-sent-events.html#reestablish-the-connection (step 5.3.)

This is causing us to fail a couple of EventSource web-platform-tests which are passing in both Chrome & Firefox.

No new tests, rebaselined existing tests.

  • platform/network/cf/ResourceRequestCFNet.cpp:

(WebCore::setHeaderFields):

  • platform/network/cf/ResourceRequestCFNet.h:

(WebCore::httpHeaderValueUsingSuitableEncoding):

  • platform/network/cocoa/ResourceRequestCocoa.mm:

(WebCore::ResourceRequest::doUpdatePlatformRequest):

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r265002 r265014  
     12020-07-28  Chris Dumez  <cdumez@apple.com>
     2
     3        [EventSource] WebKit fails to UTF-8 encode the Last-Event-ID HTTP header value
     4        https://bugs.webkit.org/show_bug.cgi?id=214860
     5
     6        Reviewed by Alex Christensen and Darin Adler.
     7
     8        Rebaseline a couple of web-platform-tests that are now passing.
     9
     10        * web-platform-tests/eventsource/format-field-id-2-expected.txt:
     11        * web-platform-tests/eventsource/format-field-id-expected.txt:
     12
    1132020-07-28  Clark Wang  <clark_wang@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/eventsource/format-field-id-2-expected.txt

    r220733 r265014  
    11
    2 FAIL EventSource: Last-Event-ID (2) assert_equals: expected "hello" but got "…"
     2PASS EventSource: Last-Event-ID (2)
    33
  • trunk/LayoutTests/imported/w3c/web-platform-tests/eventsource/format-field-id-expected.txt

    r220733 r265014  
    11
    2 FAIL EventSource: Last-Event-ID assert_equals: expected "hello" but got "…"
     2PASS EventSource: Last-Event-ID
    33
  • trunk/Source/WebCore/ChangeLog

    r265003 r265014  
     12020-07-28  Chris Dumez  <cdumez@apple.com>
     2
     3        [EventSource] WebKit fails to UTF-8 encode the Last-Event-ID HTTP header value
     4        https://bugs.webkit.org/show_bug.cgi?id=214860
     5
     6        Reviewed by Alex Christensen and Darin Adler.
     7
     8        WebKit fails to UTF-8 encode the Last-Event-ID HTTP header value for EventSource.
     9
     10        The specification is here:
     11        https://html.spec.whatwg.org/multipage/server-sent-events.html#reestablish-the-connection (step 5.3.)
     12
     13        This is causing us to fail a couple of EventSource web-platform-tests which are passing in both Chrome & Firefox.
     14
     15        No new tests, rebaselined existing tests.
     16
     17        * platform/network/cf/ResourceRequestCFNet.cpp:
     18        (WebCore::setHeaderFields):
     19        * platform/network/cf/ResourceRequestCFNet.h:
     20        (WebCore::httpHeaderValueUsingSuitableEncoding):
     21        * platform/network/cocoa/ResourceRequestCocoa.mm:
     22        (WebCore::ResourceRequest::doUpdatePlatformRequest):
     23
    1242020-07-28  Fujii Hironori  <Hironori.Fujii@sony.com>
    225
  • trunk/Source/WebCore/platform/network/cf/ResourceRequestCFNet.cpp

    r264811 r265014  
    121121
    122122    for (const auto& header : requestHeaders)
    123         CFURLRequestSetHTTPHeaderFieldValue(request, header.key.createCFString().get(), header.value.createCFString().get());
     123        CFURLRequestSetHTTPHeaderFieldValue(request, header.key.createCFString().get(), httpHeaderValueUsingSuitableEncoding(header).get());
    124124}
    125125
  • trunk/Source/WebCore/platform/network/cf/ResourceRequestCFNet.h

    r264811 r265014  
    2626#pragma once
    2727
     28#include "HTTPHeaderMap.h"
    2829#include "ResourceLoadPriority.h"
    2930#include "ResourceRequestBase.h"
     
    8485}
    8586
     87inline RetainPtr<CFStringRef> httpHeaderValueUsingSuitableEncoding(HTTPHeaderMap::const_iterator::KeyValue header)
     88{
     89    if (header.keyAsHTTPHeaderName && *header.keyAsHTTPHeaderName == HTTPHeaderName::LastEventID && !header.value.isAllASCII()) {
     90        auto utf8Value = header.value.utf8();
     91        // Constructing a string with the UTF-8 bytes but claiming that it’s Latin-1 is the way to get CFNetwork to put those UTF-8 bytes on the wire.
     92        return adoptCF(CFStringCreateWithBytes(nullptr, reinterpret_cast<const UInt8*>(utf8Value.data()), utf8Value.length(), kCFStringEncodingISOLatin1, false));
     93    }
     94    return header.value.createCFString();
     95}
     96
    8697} // namespace WebCore
  • trunk/Source/WebCore/platform/network/cocoa/ResourceRequestCocoa.mm

    r262708 r265014  
    194194    for (NSString *oldHeaderName in [nsRequest allHTTPHeaderFields])
    195195        [nsRequest setValue:nil forHTTPHeaderField:oldHeaderName];
    196     for (const auto& header : httpHeaderFields())
    197         [nsRequest setValue:header.value forHTTPHeaderField:header.key];
     196    for (const auto& header : httpHeaderFields()) {
     197        auto encodedValue = httpHeaderValueUsingSuitableEncoding(header);
     198        [nsRequest setValue:(__bridge NSString *)encodedValue.get() forHTTPHeaderField:header.key];
     199    }
    198200
    199201    [nsRequest setContentDispositionEncodingFallbackArray:createNSArray(m_responseContentDispositionEncodingFallbackArray, [] (auto& name) -> NSNumber * {
Note: See TracChangeset for help on using the changeset viewer.