Commit c0120720 authored by davidben@chromium.org's avatar davidben@chromium.org

Encode the Last-Event-ID header in EventSource as UTF-8.

HTTP headers are byte strings, so anything outside of
ASCII needs to be explicitly encoded one way or another.

BUG=429569

Review URL: https://codereview.chromium.org/836823002

git-svn-id: svn://svn.chromium.org/blink/trunk@201248 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent be8b51b8
...@@ -5,11 +5,11 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE ...@@ -5,11 +5,11 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
PASS es.readyState is es.CONNECTING PASS es.readyState is es.CONNECTING
PASS es.readyState is es.OPEN PASS es.readyState is es.OPEN
PASS evt.lastEventId is "77" PASS evt.lastEventId is "77"
PASS es.readyState is es.CONNECTING PASS es.readyState is es.CONNECTING
PASS es.readyState is es.OPEN PASS es.readyState is es.OPEN
PASS evt.data is "77" PASS evt.data is "77"
PASS evt.lastEventId is "77" PASS evt.lastEventId is "77"
PASS es.readyState is es.CLOSED PASS es.readyState is es.CLOSED
PASS successfullyParsed is true PASS successfullyParsed is true
......
...@@ -5,7 +5,8 @@ $lastEventId = $_SERVER['HTTP_LAST_EVENT_ID']; ...@@ -5,7 +5,8 @@ $lastEventId = $_SERVER['HTTP_LAST_EVENT_ID'];
if ($lastEventId) if ($lastEventId)
echo "data: $lastEventId\n\n"; echo "data: $lastEventId\n\n";
else { else {
echo "id: 77\n"; # Include a non-ASCII character to test the client encodes it correctly.
echo "id: 77☃\n";
echo "retry: 300\n"; echo "retry: 300\n";
echo "data: hello\n\n"; echo "data: hello\n\n";
echo "data: discarded"; echo "data: discarded";
......
...@@ -24,8 +24,8 @@ var evt; ...@@ -24,8 +24,8 @@ var evt;
es.onmessage = function (arg) { es.onmessage = function (arg) {
evt = arg; evt = arg;
if (errCount) if (errCount)
shouldBeEqualToString("evt.data", "77"); shouldBeEqualToString("evt.data", "77\u2603");
shouldBeEqualToString("evt.lastEventId", "77"); shouldBeEqualToString("evt.lastEventId", "77\u2603");
}; };
es.onerror = function () { es.onerror = function () {
......
...@@ -6,11 +6,11 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE ...@@ -6,11 +6,11 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
Starting worker: ../script-tests/eventsource-reconnect.js Starting worker: ../script-tests/eventsource-reconnect.js
PASS [Worker] es.readyState is es.CONNECTING PASS [Worker] es.readyState is es.CONNECTING
PASS [Worker] es.readyState is es.OPEN PASS [Worker] es.readyState is es.OPEN
PASS [Worker] evt.lastEventId is "77" PASS [Worker] evt.lastEventId is "77"
PASS [Worker] es.readyState is es.CONNECTING PASS [Worker] es.readyState is es.CONNECTING
PASS [Worker] es.readyState is es.OPEN PASS [Worker] es.readyState is es.OPEN
PASS [Worker] evt.data is "77" PASS [Worker] evt.data is "77"
PASS [Worker] evt.lastEventId is "77" PASS [Worker] evt.lastEventId is "77"
PASS [Worker] es.readyState is es.CLOSED PASS [Worker] es.readyState is es.CLOSED
PASS successfullyParsed is true PASS successfullyParsed is true
......
...@@ -127,8 +127,12 @@ void EventSource::connect() ...@@ -127,8 +127,12 @@ void EventSource::connect()
request.setHTTPHeaderField("Accept", "text/event-stream"); request.setHTTPHeaderField("Accept", "text/event-stream");
request.setHTTPHeaderField("Cache-Control", "no-cache"); request.setHTTPHeaderField("Cache-Control", "no-cache");
request.setRequestContext(WebURLRequest::RequestContextEventSource); request.setRequestContext(WebURLRequest::RequestContextEventSource);
if (!m_lastEventId.isEmpty()) if (!m_lastEventId.isEmpty()) {
request.setHTTPHeaderField("Last-Event-ID", m_lastEventId); // HTTP headers are Latin-1 byte strings, but the Last-Event-ID header is encoded as UTF-8.
// TODO(davidben): This should be captured in the type of setHTTPHeaderField's arguments.
CString lastEventIdUtf8 = m_lastEventId.utf8();
request.setHTTPHeaderField("Last-Event-ID", AtomicString(reinterpret_cast<const LChar*>(lastEventIdUtf8.data()), lastEventIdUtf8.length()));
}
SecurityOrigin* origin = executionContext.securityOrigin(); SecurityOrigin* origin = executionContext.securityOrigin();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment