11import { AxiosRequestConfig } from 'axios'
2- import EventSource from 'eventsource'
2+ import { EventSource } from 'eventsource'
33import { EndpointContext } from '../adapter'
44import { calculateHttpRequestKey } from '../cache'
55import { makeLogger , sleep } from '../util'
@@ -13,7 +13,7 @@ const logger = makeLogger('SSETransport')
1313
1414export interface SSEConfig {
1515 url : string
16- eventSourceInitDict ?: EventSource . EventSourceInitDict
16+ headers ?: Record < string , string >
1717}
1818
1919/**
@@ -103,7 +103,13 @@ export class SseTransport<T extends SSETransportGenerics> extends StreamingTrans
103103 logger . debug ( 'No established connection and new subscriptions available, connecting to SSE' )
104104 const sseConfig = this . config . prepareSSEConnectionConfig ( subscriptions . new , context )
105105 this . providerDataStreamEstablished = Date . now ( )
106- this . sseConnection = new this . EventSource ( sseConfig . url , sseConfig . eventSourceInitDict )
106+ this . sseConnection = new this . EventSource ( sseConfig . url , {
107+ fetch : ( input , init ) =>
108+ fetch ( input , {
109+ ...init ,
110+ headers : { ...init ?. headers , ...sseConfig . headers } ,
111+ } ) ,
112+ } )
107113
108114 const eventHandlerGenerator = ( listener : ( typeof this . config . eventListeners ) [ 0 ] ) => {
109115 return ( e : MessageEvent ) => {
0 commit comments