You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Seems like there is no way to add Authorization header or any other headers for EventSource. Is there any reason it shouldn't be possible?
Reacted by Lars Kemmann, Nicolás Parada, Roberto Tyley, Pavel Lysenko, Ryan R Sundberg, Legokichi Duckscallion, Loïc Hoguin, Matthias Kurz, Kévin Dunglas, Liangying.Wei and 175 more
Reacted by Ole Asteo, Igor Zarvanskyi and Felipe Brostolin Ribeiro
The main reason to not allow this is that this feature can somewhat easily be written on top of fetch(). I'm not sure we need put more effort into the "legacy" XMLHttpRequest, WebSocket, and EventSource networking APIs.
Reacted by Artem Gurtovoi
Reacted by hidden_nickname, Dai, Todd Griffin, Wang Yue, Renarin and Sagar Panchal
Reacted by Roman and Dmytro Murashko
Reacted by Bojan Tomić, ivo-enmacc, Lorenzo Pieri, F. Torkashvand, ase, Thomas Gandy, AVee, Wang Yue, ilkergzlkkr, Sagar Panchal and 2 more
@annevk What would indicate a sufficient interest?
SSE is IMO a really nice standard for implementing simple web-based queue-consumers with out of the box at least once consumption semantic and I think it has very real use-cases. But as stated above it obviously lacks the following capabilities:
Provide authentication as HTTP-Header
Provide an initial Last-Event-ID-Header that can be used to step into an already partially consumed stream (e.g. to resume from a certain position after a page reload).
It's use-cases really come to shine with event-based/ reactive backends. Something that is, compared to REST, not necessarily the thing yet, but (given all the reactive/async/streaming movement going on in the backend world) seems to be relevant enough (probably needs references).
It would of course be possible to build something similar with fetch - but it would not follow any standard and assumptions like "hey this client library and that server library supports SSE - so we can probably wire them together" will no longer hold. And beside this spec there is no such thing as standard GET for event streams.
So, I'd second to keep the EventSource/SSE standard alive and move it forward to support custom headers.
Reacted by Sergey Rubanov, Lars Kemmann, Mauro Junior, Demis Bellot, Thomas Jaeckle, A. Alonso Dominguez, Romain Lalaut, Roberto Tyley, Octavia Togami, Duan Yao and 154 more
Reacted by paco76, SeRGiOJoKeR11, Shane T, Edgar Quintero, Gabriel Pureliani, Barry, Akhil Kooliyatt, Srikanth Venkatesh, Quentin Calvez, Andrew and 11 more
I'm not sure, but over the past decade I've heard this request from three people or so, which is not really enough. Also, you can continue to use server-sent events and the server-side implementations thereof, you would just need to implement the client-side bits using fetch() if you want to transmit more headers.
Reacted by Dyllan McCreary, rooton, Flavien Berwick, Thomas Gandy, Dmytro Murashko, Daniel Rodríguez Rivero, hidden_nickname, Maverick Fabroa, Felipe Brostolin Ribeiro, Lehoczky Zoltán and 5 more
Reacted by Daniel Mendes, Ashwin Shankara Lingam, ArtistHam, Mohammad Noushad Siddiqi, Oleg A., Thomas Gandy, Ami and Maverick Fabroa
Make it four. :) We recently chose SSE over Web Sockets for a reactive app because it's much simpler to program against and the built-in reliability is nice. Having to work around the lack of custom headers support by putting the authorization token in the query string is probably the one thing really missing from the standard. Why should we pause use of a perfectly good technology and wait until replacements come out?
Reacted by Sergey Rubanov, Daniel Wegener, Kellen Green, Mauro Junior, Demis Bellot, Mr. Pill, Nicolás Parada, Thomas Jaeckle, A. Alonso Dominguez, Romain Lalaut and 112 more
Given the (renewed) interest in this I'll reopen. We'll still need implementer interest.
Reacted by Sergey Rubanov, Matthias Kurz, Eugene Timofeev, Lars Kemmann, Daniel Wegener, Morgan Touverey Quilling, Джон, просто Джон, Kamal Gill, Rob, Pablo Alejandro Costesich and 84 more
Reacted by Sergey Rubanov, Matthias Kurz, Lars Kemmann, Daniel Wegener, Matthew McEachen, Morgan Touverey Quilling, Rob, Pablo Alejandro Costesich, lpd-au, Martin Bayly and 37 more
Reacted by paco76, Tjeerd Bakker, Alejuanito, Barry, Sai Kumar, Ashwin Shankara Lingam, Srikanth Venkatesh, Quentin Calvez, ArtistHam, Wojciech Połowniak and 5 more
I don't think complaining here is going to result in any outcome.
Request headers should be standardized. EventSouce is available in baseline but it is useless for most practical use-cases that require request headers.
This feature should either be deprecated and removed or extended to include request headers. Otherwise, it is just a bloat.
Because, backend devs will test their SSE endpoints on postman and opt to use SSE instead of websocket because SSE in postman allows request headers. Not including it in the spec is a very bad idea.
Reacted by hidden_nickname, AVee, Matt W, Sagar Panchal, Daniel Rodríguez Rivero, newclarityex, Sriram Aleti, Marvin Müller and J.Doe
I came across this because I was looking for a solution to setting Authorization headers on this too. But it occurs to me that the most useful part of EventSource is actually in the parsing of the text/event-stream body, while fetch with streams handles the network side of things well.
I'm thinking rather than adding extra options to the EventSource constructor to handle Authorization, Last-Event-ID or whatever other options someone might want to use, the easiest and most flexible solution would be to consider leaving EventSource constructor as-is, but providing an alternative EventSource.fromStream(readableStream). Then we could open the connection using fetch, then call EventSource.fromStream(response.body).
That has the advantage of being easy to feature detect or polyfill by checking if fromStream exists, effectively separates the network handling of the feature from the event stream processing, and opens it up to getting any events from any other readable stream source.
Edit: EventSource.fromReadableStream() is probably a better name, and makes it clear it's not supporting NodeJS Stream API, which would be a relevant distinction for EventSource implementations made for node environments.
Reacted by Niki, dcop, Sagar Panchal, Marvin Müller, Clément Maisonhaute, Timo Tijhof, Bruno Heridet and Hunter Perrin
I had another look into how this might be addressed and the feasibility of speccing an EventSource.fromReadableStream() method that I proposed in #2177 (comment) and it seems workable, but there's a few issues that would need to be decided.
What should eventSource.url return when it's an instance created from a ReadableStream? Could be either an empty string or something like about:stream.
eventSource.withCredentials would just return false.
The reconnection time and last event ID are currently handled internally, but they would need to be exposed for applications to use them in their own reconnection logic, most likely via new reconnectionTime and lastEventId properties. It's not clear what eventSource.reconnectionTime would return prior to the server setting a value with the retry field. The current spec defines the default reconnection time as implementation defined. It could either return null, expose the implementation defined value, or otherwise the spec could define a set default value if there was consensus among implementers about what it should be.
A TypeError would have to be thrown if the ReadableStream was locked.
readyState would have to start OPEN. The CONNECTING state doesn't make sense when EventSource doesn't control the connection.
There's no reconnection behaviour. Once the stream signals done, then it's an error and it transitions to CLOSED. Applications could use a TransformStream, create EventSource.fromReadableStream(ts.readable) and pipe fetch response bodies to it using response.body.pipeTo(ts.writable, { preventClose: true }) to keep the stream open and handle reconnection independently.
Reacted by Timo Tijhof, Matthias Kurz, Daniel Wegener, Frederik Heber and Chance Snow
Activity
[-]Authorization header for EvenSource[/-][+]Setting headers for EvenSource[/+]annevk commentedon Dec 15, 2016
The main reason to not allow this is that this feature can somewhat easily be written on top of
fetch(). I'm not sure we need put more effort into the "legacy"XMLHttpRequest,WebSocket, andEventSourcenetworking APIs.chicoxyzzy commentedon Dec 15, 2016
Hmm... I have not seen any SSE alternatives based on Fetch yet. Do you know any implementations?
annevk commentedon Dec 15, 2016
No, sorry. It's also still a little early since only Chrome supports https://streams.spec.whatwg.org/ for now. But you can build any kind of abstraction on top of that. You would also no longer be limited by the SSE format and such.
chicoxyzzy commentedon Dec 15, 2016
How should we cancel a Fetch stream? Cancelable Promises proposal is withdrawn.
domenic commentedon Dec 15, 2016
stream.cancel()annevk commentedon Dec 16, 2016
Closing this since I don't think we'll be able to find sufficient interest to extend this API.
danielwegener commentedon Feb 8, 2017
@annevk What would indicate a sufficient interest?
SSE is IMO a really nice standard for implementing simple web-based queue-consumers with out of the box at least once consumption semantic and I think it has very real use-cases. But as stated above it obviously lacks the following capabilities:
Last-Event-ID-Header that can be used to step into an already partially consumed stream (e.g. to resume from a certain position after a page reload).There are also quite a lot active server-side implementations of SSE out there.
It's use-cases really come to shine with event-based/ reactive backends. Something that is, compared to REST, not necessarily the thing yet, but (given all the reactive/async/streaming movement going on in the backend world) seems to be relevant enough (probably needs references).
It would of course be possible to build something similar with fetch - but it would not follow any standard and assumptions like "hey this client library and that server library supports SSE - so we can probably wire them together" will no longer hold. And beside this spec there is no such thing as standard
GETfor event streams.So, I'd second to keep the EventSource/SSE standard alive and move it forward to support custom headers.
annevk commentedon Feb 8, 2017
I'm not sure, but over the past decade I've heard this request from three people or so, which is not really enough. Also, you can continue to use server-sent events and the server-side implementations thereof, you would just need to implement the client-side bits using
fetch()if you want to transmit more headers.LarsKemmann commentedon Apr 11, 2017
Make it four. :) We recently chose SSE over Web Sockets for a reactive app because it's much simpler to program against and the built-in reliability is nice. Having to work around the lack of custom headers support by putting the authorization token in the query string is probably the one thing really missing from the standard. Why should we pause use of a perfectly good technology and wait until replacements come out?
kmayer commentedon Jul 10, 2017
I have a working implementation, forked from Yaffle's polyfill.
Yaffle/EventSource@master...kmayer:kmayer-2
annevk commentedon Jul 11, 2017
Given the (renewed) interest in this I'll reopen. We'll still need implementer interest.
64 remaining items
clients/web: use dedicated library to connect to SSE
clients/web: use dedicated library to connect to SSE
clients/web: use dedicated library to connect to SSE
DMurashko commentedon Apr 14, 2025
sagarpanchal commentedon Apr 19, 2025
I don't think complaining here is going to result in any outcome.
Request headers should be standardized. EventSouce is available in baseline but it is useless for most practical use-cases that require request headers.
Most of the devs who have to pass Auth headers end up using eventsource npm package https://www.npmjs.com/package/eventsource. This package has 4,613,039 weekly downloads, just because it allows custom headers, so we don't have to prompt users to enable cookies, if it's disabled.
This feature should either be deprecated and removed or extended to include request headers. Otherwise, it is just a bloat.
Because, backend devs will test their SSE endpoints on postman and opt to use SSE instead of websocket because SSE in postman allows request headers. Not including it in the spec is a very bad idea.
ezekielokoduwa commentedon Apr 19, 2025
lachlanhunt commentedon Jun 19, 2025
I came across this because I was looking for a solution to setting Authorization headers on this too. But it occurs to me that the most useful part of EventSource is actually in the parsing of the text/event-stream body, while fetch with streams handles the network side of things well.
I'm thinking rather than adding extra options to the EventSource constructor to handle
Authorization,Last-Event-IDor whatever other options someone might want to use, the easiest and most flexible solution would be to consider leaving EventSource constructor as-is, but providing an alternativeEventSource.fromStream(readableStream). Then we could open the connection using fetch, then callEventSource.fromStream(response.body).That has the advantage of being easy to feature detect or polyfill by checking if
fromStreamexists, effectively separates the network handling of the feature from the event stream processing, and opens it up to getting any events from any other readable stream source.Edit: EventSource.fromReadableStream() is probably a better name, and makes it clear it's not supporting NodeJS Stream API, which would be a relevant distinction for EventSource implementations made for node environments.
danielo515 commentedon Jul 29, 2025
Kludex commentedon Aug 4, 2025
Can someone please point out how we can move forward here? I don't want to complain bluntly.
I'm just really interested in having
Authorizationheaders intoWebSocketandEventSource.annevk commentedon Aug 4, 2025
#2177 (comment) has the steps that need to be taken.
Yaropolki4 commentedon Oct 23, 2025
lachlanhunt commentedon Mar 16, 2026
I had another look into how this might be addressed and the feasibility of speccing an
EventSource.fromReadableStream()method that I proposed in #2177 (comment) and it seems workable, but there's a few issues that would need to be decided.eventSource.urlreturn when it's an instance created from aReadableStream? Could be either an empty string or something likeabout:stream.eventSource.withCredentialswould just returnfalse.reconnectionTimeandlastEventIdproperties. It's not clear whateventSource.reconnectionTimewould return prior to the server setting a value with theretryfield. The current spec defines the default reconnection time as implementation defined. It could either returnnull, expose the implementation defined value, or otherwise the spec could define a set default value if there was consensus among implementers about what it should be.TypeErrorwould have to be thrown if theReadableStreamwas locked.readyStatewould have to startOPEN. TheCONNECTINGstate doesn't make sense whenEventSourcedoesn't control the connection.CLOSED. Applications could use aTransformStream, createEventSource.fromReadableStream(ts.readable)and pipe fetch response bodies to it usingresponse.body.pipeTo(ts.writable, { preventClose: true })to keep the stream open and handle reconnection independently.lachlanhunt commentedon Mar 18, 2026
2 of the 3 steps to get this pushed through are drafted.
fix: replace abandoned SSE dependency with a maintained one
Harden sync correctness, account provisioning, and API safety (#987)