Truly independent web browser
LibWeb: Send the EventSource `Last-Event-ID` header value as UTF-8
Tim Ledbetter43c5a2a5c459
diff --git a/Libraries/LibWeb/HTML/EventSource.cpp b/Libraries/LibWeb/HTML/EventSource.cppindex 533e659b4a3..c9181d31a7c 100644--- a/Libraries/LibWeb/HTML/EventSource.cpp+++ b/Libraries/LibWeb/HTML/EventSource.cpp@@ -365,8 +365,7 @@ void EventSource::reestablish_the_connection()// 1. Let lastEventIDValue be the EventSource object's last event ID string, encoded as UTF-8.auto last_event_id_value = m_last_event_id.to_utf8();// 2. Set (`Last-Event-ID`, lastEventIDValue) in request's header list.- auto header = HTTP::Header::isomorphic_encode("Last-Event-ID"sv, last_event_id_value);- request->header_list()->set(move(header));+ request->header_list()->set({ "Last-Event-ID"sv, last_event_id_value.to_byte_string() });}// 4. Fetch request and process the response obtained in this fashion, if any, as described earlier in thisdiff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 5f7100ec434..5d99f03770e 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -275,7 +275,13 @@ Text/input/wpt-import/html/semantics/scripting-1/the-script-element/css-module/iText/input/wpt-import/html/semantics/scripting-1/the-script-element/css-module/css-module-worker-test.htmlText/input/wpt-import/eventsource/format-bom-2.any.htmlText/input/wpt-import/eventsource/format-bom.any.html+Text/input/wpt-import/eventsource/format-field-id-2.any.html+Text/input/wpt-import/eventsource/format-field-id-2.any.worker.htmlText/input/wpt-import/eventsource/format-field-id-null.window.html+Text/input/wpt-import/eventsource/format-field-id-redirect.any.html+Text/input/wpt-import/eventsource/format-field-id-redirect.any.worker.html+Text/input/wpt-import/eventsource/format-field-id.any.html+Text/input/wpt-import/eventsource/format-field-id.any.worker.htmlText/input/wpt-import/eventsource/format-field-retry-bogus.any.htmlText/input/wpt-import/eventsource/format-field-retry-bogus.any.worker.htmlText/input/wpt-import/eventsource/format-field-retry.any.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id-2.any.txt b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id-2.any.txtnew file mode 100644index 00000000000..eb4dcb2ec17--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id-2.any.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass EventSource: Last-Event-ID (2)\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id-2.any.worker.txt b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id-2.any.worker.txtnew file mode 100644index 00000000000..eb4dcb2ec17--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id-2.any.worker.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass EventSource: Last-Event-ID (2)\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id-redirect.any.txt b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id-redirect.any.txtnew file mode 100644index 00000000000..430ee4d1952--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id-redirect.any.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass EventSource: Last-Event-ID after redirect\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id-redirect.any.worker.txt b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id-redirect.any.worker.txtnew file mode 100644index 00000000000..430ee4d1952--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id-redirect.any.worker.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass EventSource: Last-Event-ID after redirect\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id.any.txt b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id.any.txtnew file mode 100644index 00000000000..062494a1827--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id.any.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass EventSource: Last-Event-ID\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id.any.worker.txt b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id.any.worker.txtnew file mode 100644index 00000000000..062494a1827--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/eventsource/format-field-id.any.worker.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass EventSource: Last-Event-ID\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-2.any.html b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-2.any.htmlnew file mode 100644index 00000000000..505db822478--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-2.any.html@@ -0,0 +1,15 @@+<!doctype html>+<meta charset=utf-8>+<title>EventSource: Last-Event-ID (2)</title>+<script>+self.GLOBAL = {+ isWindow: function() { return true; },+ isWorker: function() { return false; },+ isShadowRealm: function() { return false; },+};+</script>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>++<div id=log></div>+<script src="../eventsource/format-field-id-2.any.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-2.any.js b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-2.any.jsnew file mode 100644index 00000000000..9933f46b875--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-2.any.js@@ -0,0 +1,25 @@+// META: title=EventSource: Last-Event-ID (2)+ var test = async_test()+ test.step(function() {+ var source = new EventSource("resources/last-event-id.py"),+ counter = 0+ source.onmessage = function(e) {+ test.step(function() {+ if(e.data == "hello" && counter == 0) {+ counter+++ assert_equals(e.lastEventId, "…")+ } else if(counter == 1) {+ counter+++ assert_equals("…", e.data)+ assert_equals("…", e.lastEventId)+ } else if(counter == 2) {+ counter+++ assert_equals("…", e.data)+ assert_equals("…", e.lastEventId)+ source.close()+ test.done()+ } else+ assert_unreached()+ })+ }+ })diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-2.any.worker.html b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-2.any.worker.htmlnew file mode 100644index 00000000000..3bed4b03dfc--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-2.any.worker.html@@ -0,0 +1,9 @@+<!doctype html>+<meta charset=utf-8>+<title>EventSource: Last-Event-ID (2)</title>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<div id=log></div>+<script>+fetch_tests_from_worker(new Worker("../eventsource/format-field-id-2.any.worker.js"));+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-2.any.worker.js b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-2.any.worker.jsnew file mode 100644index 00000000000..819e2a72bb9--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-2.any.worker.js@@ -0,0 +1,10 @@++self.GLOBAL = {+ isWindow: function() { return false; },+ isWorker: function() { return true; },+ isShadowRealm: function() { return false; },+};+importScripts("/resources/testharness.js");+self.META_TITLE = "EventSource: Last-Event-ID (2)";+importScripts("/eventsource/format-field-id-2.any.js");+done();diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-redirect.any.html b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-redirect.any.htmlnew file mode 100644index 00000000000..9e6efa30382--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-redirect.any.html@@ -0,0 +1,15 @@+<!doctype html>+<meta charset=utf-8>+<title>EventSource: Last-Event-ID after redirect</title>+<script>+self.GLOBAL = {+ isWindow: function() { return true; },+ isWorker: function() { return false; },+ isShadowRealm: function() { return false; },+};+</script>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>++<div id=log></div>+<script src="../eventsource/format-field-id-redirect.any.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-redirect.any.js b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-redirect.any.jsnew file mode 100644index 00000000000..9c09b03a2a0--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-redirect.any.js@@ -0,0 +1,20 @@+// META: title=EventSource: Last-Event-ID after redirect+ var test = async_test()+ test.step(function() {+ var source = new EventSource("/common/redirect.py?location=/eventsource/resources/last-event-id.py"),+ seenhello = false+ source.onmessage = function(e) {+ test.step(function() {+ if(e.data == "hello" && !seenhello) {+ seenhello = true+ assert_equals(e.lastEventId, "…")+ } else if(seenhello) {+ assert_equals("…", e.data)+ assert_equals("…", e.lastEventId)+ source.close()+ test.done()+ } else+ assert_unreached()+ })+ }+ })diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-redirect.any.worker.html b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-redirect.any.worker.htmlnew file mode 100644index 00000000000..851e1b818e3--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-redirect.any.worker.html@@ -0,0 +1,9 @@+<!doctype html>+<meta charset=utf-8>+<title>EventSource: Last-Event-ID after redirect</title>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<div id=log></div>+<script>+fetch_tests_from_worker(new Worker("../eventsource/format-field-id-redirect.any.worker.js"));+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-redirect.any.worker.js b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-redirect.any.worker.jsnew file mode 100644index 00000000000..cb8370ca198--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id-redirect.any.worker.js@@ -0,0 +1,10 @@++self.GLOBAL = {+ isWindow: function() { return false; },+ isWorker: function() { return true; },+ isShadowRealm: function() { return false; },+};+importScripts("/resources/testharness.js");+self.META_TITLE = "EventSource: Last-Event-ID after redirect";+importScripts("/eventsource/format-field-id-redirect.any.js");+done();diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id.any.html b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id.any.htmlnew file mode 100644index 00000000000..b118999f001--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id.any.html@@ -0,0 +1,15 @@+<!doctype html>+<meta charset=utf-8>+<title>EventSource: Last-Event-ID</title>+<script>+self.GLOBAL = {+ isWindow: function() { return true; },+ isWorker: function() { return false; },+ isShadowRealm: function() { return false; },+};+</script>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>++<div id=log></div>+<script src="../eventsource/format-field-id.any.js"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id.any.js b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id.any.jsnew file mode 100644index 00000000000..26f1aea7091--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id.any.js@@ -0,0 +1,21 @@+// META: title=EventSource: Last-Event-ID+ var test = async_test()+ test.step(function() {+ var source = new EventSource("resources/last-event-id.py"),+ seenhello = false+ source.onmessage = function(e) {+ test.step(function() {+ if(e.data == "hello" && !seenhello) {+ seenhello = true+ assert_equals(e.lastEventId, "…")+ } else if(seenhello) {+ assert_equals("…", e.data)+ assert_equals("…", e.lastEventId)+ source.close()+ test.done()+ } else+ assert_unreached()+ })+ }+ })+diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id.any.worker.html b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id.any.worker.htmlnew file mode 100644index 00000000000..03243419269--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id.any.worker.html@@ -0,0 +1,9 @@+<!doctype html>+<meta charset=utf-8>+<title>EventSource: Last-Event-ID</title>+<script src="../resources/testharness.js"></script>+<script src="../resources/testharnessreport.js"></script>+<div id=log></div>+<script>+fetch_tests_from_worker(new Worker("../eventsource/format-field-id.any.worker.js"));+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id.any.worker.js b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id.any.worker.jsnew file mode 100644index 00000000000..823ba8c254a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/eventsource/format-field-id.any.worker.js@@ -0,0 +1,10 @@++self.GLOBAL = {+ isWindow: function() { return false; },+ isWorker: function() { return true; },+ isShadowRealm: function() { return false; },+};+importScripts("/resources/testharness.js");+self.META_TITLE = "EventSource: Last-Event-ID";+importScripts("/eventsource/format-field-id.any.js");+done();