+
Skip to content

Add an extension to SSE to attach metadata to events #617

Open
@dunglas

Description

@dunglas

A current limitation of Mercure is that attaching metadata (such as HTTP headers) to a resource is not handled at the protocol level. Users need to take care of this themselves by crafting a custom data structure transmitted in the SSE events.

We could allow attaching metadata to an update by allowing to send custom fields in the events. Currently, the SSE spec states the custom fields are ignored: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation

However, in the context of transmitting HTTP resources through SSE, it could be interesting to be able to use custom fields as to attach custom metadata in sync with HTTP headers:

id: foo
ETag: abcd
Version: 1234
data: {"json": "lorem ipsum"}

This would be convenient to replace metadata attached with a resource representation send through Mercure in a web browser.
The extra properties could be added as new properties of the event object passed as parameters of callbacks:

const es = new EventSource("/.well-known/mercure");
es.onmessage = (e) => console.log(e.ETag, e.Version);

Supporting this extension would require browser collaboration.
In the meantime, the existing EventSource polyfills could easily be patched to support this new feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    pinnedThe issue must not be marked as stalespecSpec-related issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载