Skip to content

Commit

Permalink
Fetch's Response.statusText is unexpectedly the full http status line…
Browse files Browse the repository at this point in the history
… for HTTP/2 responses

https://bugs.webkit.org/show_bug.cgi?id=176479

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2017-09-08
Reviewed by Alex Christensen.

Source/WebCore:

Test: http/wpt/fetch/response-status-text.html

HTTP/2 doesn't include a status reason phrase. So the "status line"
ends up just being the version and status code. Fallback to the empty
string instead of the full line.

* platform/network/HTTPParsers.cpp:
(WebCore::extractReasonPhraseFromHTTPStatusLine):

Source/WebKit:

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::initializeNetworkProcess):
Initialize AtomicString statics like emptyAtom().

LayoutTests:

* http/wpt/fetch/resources/status-garbage.asis: Added.
* http/wpt/fetch/resources/status-normal.txt: Added.
* http/wpt/fetch/resources/status-with-message.asis: Added.
* http/wpt/fetch/resources/status-without-message.asis: Added.
Various text HTTP responses with different status lines.

* http/wpt/fetch/response-status-text-expected.txt: Added.
* http/wpt/fetch/response-status-text.html: Added.
Test the Fetch Response's status / statusText for different HTTP status lines.
The status without a message is similiar to HTTP/2 because HTTP/2 only
has a :status pseudo-header and lacks a reason phrase.

Canonical link: https://commits.webkit.org/193157@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221804 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
JosephPecoraro authored and webkit-commit-queue committed Sep 9, 2017
1 parent 3cc77ed commit 93719e1
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 0 deletions.
19 changes: 19 additions & 0 deletions LayoutTests/ChangeLog
@@ -1,3 +1,22 @@
2017-09-08 Joseph Pecoraro <pecoraro@apple.com>

Fetch's Response.statusText is unexpectedly the full http status line for HTTP/2 responses
https://bugs.webkit.org/show_bug.cgi?id=176479

Reviewed by Alex Christensen.

* http/wpt/fetch/resources/status-garbage.asis: Added.
* http/wpt/fetch/resources/status-normal.txt: Added.
* http/wpt/fetch/resources/status-with-message.asis: Added.
* http/wpt/fetch/resources/status-without-message.asis: Added.
Various text HTTP responses with different status lines.

* http/wpt/fetch/response-status-text-expected.txt: Added.
* http/wpt/fetch/response-status-text.html: Added.
Test the Fetch Response's status / statusText for different HTTP status lines.
The status without a message is similiar to HTTP/2 because HTTP/2 only
has a :status pseudo-header and lacks a reason phrase.

2017-09-08 Said Abou-Hallawa <sabouhallawa@apple.com>

Implement the attribute HTMLImageElement.async
Expand Down
1 change: 1 addition & 0 deletions LayoutTests/http/wpt/fetch/resources/status-garbage.asis
@@ -0,0 +1 @@
ALPHA BETA
1 change: 1 addition & 0 deletions LayoutTests/http/wpt/fetch/resources/status-normal.txt
@@ -0,0 +1 @@
Intentionally empty.
@@ -0,0 +1 @@
HTTP/1.1 200 Alpha
@@ -0,0 +1 @@
HTTP/1.1 200
6 changes: 6 additions & 0 deletions LayoutTests/http/wpt/fetch/response-status-text-expected.txt
@@ -0,0 +1,6 @@

PASS Normal status text.
PASS Abnormal status text.
PASS Empty status text.
PASS Garbage status line.

38 changes: 38 additions & 0 deletions LayoutTests/http/wpt/fetch/response-status-text.html
@@ -0,0 +1,38 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Response status and statusText given various HTTP response status lines.</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
</head>
<body>
<script>
promise_test(test => {
return fetch("resources/status-normal.txt").then((response) => {
assert_equals(response.status, 200);
assert_equals(response.statusText, "OK");
});
}, "Normal status text.");

promise_test(test => {
return fetch("resources/status-with-message.asis").then((response) => {
assert_equals(response.status, 200);
assert_equals(response.statusText, "Alpha");
});
}, "Abnormal status text.");

promise_test(test => {
return fetch("resources/status-without-message.asis").then((response) => {
assert_equals(response.status, 200);
assert_equals(response.statusText, "");
});
}, "Empty status text.");

promise_test(test => {
let promise = fetch("resources/status-garbage.asis");
return promise_rejects(test, new TypeError(), promise);
}, "Garbage status line.");
</script>
</body>
</html>
16 changes: 16 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,19 @@
2017-09-08 Joseph Pecoraro <pecoraro@apple.com>

Fetch's Response.statusText is unexpectedly the full http status line for HTTP/2 responses
https://bugs.webkit.org/show_bug.cgi?id=176479

Reviewed by Alex Christensen.

Test: http/wpt/fetch/response-status-text.html

HTTP/2 doesn't include a status reason phrase. So the "status line"
ends up just being the version and status code. Fallback to the empty
string instead of the full line.

* platform/network/HTTPParsers.cpp:
(WebCore::extractReasonPhraseFromHTTPStatusLine):

2017-09-08 Said Abou-Hallawa <sabouhallawa@apple.com>

Implement the attribute HTMLImageElement.async
Expand Down
6 changes: 6 additions & 0 deletions Source/WebCore/platform/network/HTTPParsers.cpp
Expand Up @@ -478,12 +478,18 @@ ContentTypeOptionsDisposition parseContentTypeOptionsHeader(const String& header
return ContentTypeOptionsNone;
}

// For example: "HTTP/1.1 200 OK" => "OK".
// Note that HTTP/2 does not include a reason phrase, so we return the empty atom.
AtomicString extractReasonPhraseFromHTTPStatusLine(const String& statusLine)
{
StringView view = statusLine;
size_t spacePos = view.find(' ');

// Remove status code from the status line.
spacePos = view.find(' ', spacePos + 1);
if (spacePos == notFound)
return emptyAtom();

return view.substring(spacePos + 1).toAtomicString();
}

Expand Down
11 changes: 11 additions & 0 deletions Source/WebKit/ChangeLog
@@ -1,3 +1,14 @@
2017-09-08 Joseph Pecoraro <pecoraro@apple.com>

Fetch's Response.statusText is unexpectedly the full http status line for HTTP/2 responses
https://bugs.webkit.org/show_bug.cgi?id=176479

Reviewed by Alex Christensen.

* NetworkProcess/NetworkProcess.cpp:
(WebKit::NetworkProcess::initializeNetworkProcess):
Initialize AtomicString statics like emptyAtom().

2017-09-08 Commit Queue <commit-queue@webkit.org>

Unreviewed, rolling out r221773.
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/NetworkProcess/NetworkProcess.cpp
Expand Up @@ -66,6 +66,7 @@
#include <pal/SessionID.h>
#include <wtf/OptionSet.h>
#include <wtf/RunLoop.h>
#include <wtf/text/AtomicString.h>
#include <wtf/text/CString.h>

#if ENABLE(SEC_ITEM_SHIM)
Expand Down Expand Up @@ -207,6 +208,7 @@ void NetworkProcess::initializeNetworkProcess(NetworkProcessCreationParameters&&
platformInitializeNetworkProcess(parameters);

WTF::Thread::setCurrentThreadIsUserInitiated();
AtomicString::init();

m_suppressMemoryPressureHandler = parameters.shouldSuppressMemoryPressureHandler;
m_loadThrottleLatency = parameters.loadThrottleLatency;
Expand Down

0 comments on commit 93719e1

Please sign in to comment.