EventSource / eventsource

EventSource client for Node.js and Browser (polyfill)
MIT License
908 stars 252 forks source link

Question about eventSourceInitDict #296

Closed xtianus79 closed 2 years ago

xtianus79 commented 2 years ago

When you say this

You can define custom HTTP headers for the initial HTTP request. This can be useful for e.g. sending cookies or to specify an initial Last-Event-ID value.

Does that mean on open? where would that appear? Also, what would be a use case of this?

joeybaker commented 2 years ago

This is an example of setting headers: https://github.com/EventSource/eventsource/blob/master/test/eventsource_test.js#L518-L523

You could use this for anything from authorization to Last-Event-ID which can be used to tell the server how much historical information the client needs. A common scenario is when the client keeps a cache of events and wants to understand the "state of the world".