sysid / sse-starlette

BSD 3-Clause "New" or "Revised" License
504 stars 35 forks source link

Put id: after data: #58

Closed cancan101 closed 1 year ago

cancan101 commented 1 year ago

https://javascript.info/server-sent-events makes a good point to:

Put id: after data: Please note: the id is appended below message data by the server, to ensure that lastEventId is updated after the message is received.

However, that does not seem to be the case in the current implementation: https://github.com/sysid/sse-starlette/blob/8086dac07fc459252c127f89b8d8db5fcff65e39/sse_starlette/sse.py#L101-L112

sysid commented 1 year ago

Hallo @cancan101 , thank you for your input.

Doing a quick scan of https://html.spec.whatwg.org/multipage/server-sent-events.html I could find no spec in this regard. Since the entire payload (including id) is sent as one byte chunk I am not sure whether this is adding any benefit.

If I missed something in hte spec then this needs to change, of course.

In any case, PRs wellcome.

Regards, sysid

cancan101 commented 1 year ago

I filed a comment upstream: https://github.com/javascript-tutorial/en.javascript.info/commit/027933531e121650120f7e8385f691de99af12d2#r113921611

the note on the linked doc might have been a misinterpretation of this comment from the spec:

The second block has two fields with names "data" and "id" respectively; an event will be fired for this block, with the data "first event", and will then set the last event ID to "1" so that if the connection died between this block and the next, the server would be sent a [Last-Event-ID](https://html.spec.whatwg.org/multipage/server-sent-events.html#last-event-id) header with the value 1.

sysid commented 1 year ago

Nothing to do here. Please reopen if needed.