HTTP Authorization Header in EventSource (Server Sent Events)

前端 未结 8 2102
梦谈多话
梦谈多话 2021-02-01 01:52

I need to set an Authorization header to an HTML5 EventSource. As Server Sent Events seems to be disused since Websockets appeared, I cannot find any useful documentation. The a

8条回答
  •  忘了有多久
    2021-02-01 02:22

    This polyfill adds Authorization Header support: https://github.com/Yaffle/EventSource/

    So you can do:

    new EventSource("https://domain/stream", { authorizationHeader: "Bearer ..." });
    

提交回复
热议问题