Description
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.