Server sent events Once the end of the file is reached, any pending data must be discarded

RESOLVED FIXED

Status

()

Core
DOM: Core & HTML
RESOLVED FIXED
6 years ago
5 years ago

People

(Reporter: 4esn0k, Assigned: Wellington Fernando de Macedo)

Tracking

Trunk
x86
Windows Vista
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Reporter)

Description

6 years ago
User Agent: Opera/9.80 (Windows NT 6.0; U; Edition Next; ru) Presto/2.10.238 Version/12.00

Steps to reproduce:


according to latest spec:
Once the end of the file is reached, any pending data must be discarded. (If the file ends in the middle of an event, before the final empty line, the incomplete event is not dispatched.) - see http://dev.w3.org/html5/eventsource/


Actual results:

  var es = new EventSource('events.php');
  es.onmessage = function (e) {
    alert(e.data + ' ' + e.lastEventId);// Firefox alerts "data0 123"
  };

events.php:
   echo "id: 123\n";
    echo "data: data0";
    exit();



Expected results:

If the file ends in the middle of an event, before the final empty line, the incomplete event is not dispatched.
Also the last id field value received should be stored in a buffer and set as the EventSource's lastEventId only when the event is actually dispatched - see http://www.w3.org/Bugs/Public/show_bug.cgi?id=13761
(Assignee)

Comment 1

5 years ago
Just a commentary for clarifying future questions. According to spec:
>> event         = *( comment / field ) end-of-line
>> field         = 1*name-char [ colon [ space ] *any-char ] end-of-line
>> end-of-line   = ( cr lf / cr / lf )
>> 
>> If the file ends in the middle of an event, before the final empty line, the incomplete 
>> event is not dispatched.

So, for instance, the following code won't dispatch an event either:
>> echo "data: data0\r";
>> exit;
But this one will:
>> echo "data: data0\r\r";
>> exit;
Assignee: nobody → wfernandom2004
Status: UNCONFIRMED → NEW
Ever confirmed: true
(Assignee)

Updated

5 years ago
Status: NEW → ASSIGNED
(Assignee)

Comment 2

5 years ago
Created attachment 617246 [details] [diff] [review]
v1
Attachment #617246 - Flags: review?
(Assignee)

Comment 3

5 years ago
Comment on attachment 617246 [details] [diff] [review]
v1

Olli, just a comment, I've removed the test which was testing an invalid NCName char in the event field name because it has become obsolete due changes in the spec.
Attachment #617246 - Flags: review? → review?(bugs)
(Assignee)

Comment 4

5 years ago
https://hg.mozilla.org/try/rev/e135d9bb9f35

Comment 5

5 years ago
(Hopefully reviewing this tomorrow.)

Comment 6

5 years ago
(In reply to Wellington Fernando de Macedo from comment #1)
> Just a commentary for clarifying future questions. According to spec:
> >> event         = *( comment / field ) end-of-line
> >> field         = 1*name-char [ colon [ space ] *any-char ] end-of-line
> >> end-of-line   = ( cr lf / cr / lf )
> >> 
> >> If the file ends in the middle of an event, before the final empty line, the incomplete 
> >> event is not dispatched.
> 
> So, for instance, the following code won't dispatch an event either:
> >> echo "data: data0\r";
> >> exit;
> But this one will:
> >> echo "data: data0\r\r";
> >> exit;
Er, what. Do we need two new lines? that looks like a spec bug to me.

Comment 7

5 years ago
Comment on attachment 617246 [details] [diff] [review]
v1

Actually, perhaps it is ok.

Have you tested other browsers?
Attachment #617246 - Flags: review?(bugs) → review+

Comment 8

5 years ago
Comment on attachment 617246 [details] [diff] [review]
v1


>+++ b/content/base/test/badContentType.eventsource
>@@ -1,3 +1,5 @@
> retry:500
> event: message
> data: 1
>+
>+

Actually, why do you need 2 empty lines? Shouldn't 1 be enough
(Assignee)

Comment 9

5 years ago
>> Actually, why do you need 2 empty lines? Shouldn't 1 be enough
Actually, I think 1 empty line would be enough. But, according to the spec:

1. event         = *( comment / field ) end-of-line
2. field         = 1*name-char [ colon [ space ] *any-char ] end-of-line

Hence:
event = 1*name-char [ colon [ space ] *any-char ] end-of-line end-of-line

Also:
>> If the file ends in the *middle of an event*, *before the final* empty line,
>> the incomplete event is not dispatched.

>> Have you tested other browsers?
No, unfortunately I didn't. Anyway, if they dispatch with just one empty line then either the spec needs to be fixed or the other browsers implementations need to be fixed.
But you have the end-of-line after data: 1 and then 2 end-of-lines, so totally 3.
I think 2 should be enough, per spec
(Assignee)

Comment 11

5 years ago
Humm, I think there are 2 end-of-lines, not three:
> data: 1 LF
>+ LF
>+ EOF

isn't it?
Um, right, silly me.
I interpreted the diff in a wrong way.
(Reporter)

Comment 13

5 years ago
any updates?
(Assignee)

Comment 14

5 years ago
It is already done. Perhaps it needs just to be update to the trunk.
Argh, this wasn't just pushed to m-c. My bad.
Wellington, want to update the patch to work with trunk? If you don't have time, I can do it.
(Assignee)

Comment 16

5 years ago
Ok, no problem Olli. I'll update it tomorrow and upload again here.
Thanks!
(Assignee)

Comment 18

5 years ago
Created attachment 704732 [details] [diff] [review]
v1 updated
Attachment #617246 - Attachment is obsolete: true
Attachment #704732 - Flags: review?(bugs)
Attachment #704732 - Flags: checkin?(bugs)
Comment on attachment 704732 [details] [diff] [review]
v1 updated

tree is closed atm, so can push this right now.
Attachment #704732 - Flags: review?(bugs) → review+
(Reporter)

Comment 20

5 years ago
fine, thank you
Tryserver https://tbpl.mozilla.org/?tree=Try&rev=e1a689a9390b
Waiting for the results before pushing.
https://hg.mozilla.org/mozilla-central/rev/653199a8edea
Status: ASSIGNED → RESOLVED
Last Resolved: 5 years ago
Resolution: --- → FIXED

Updated

5 years ago
Attachment #704732 - Flags: checkin?(bugs) → checkin+
You need to log in before you can comment on or make changes to this bug.