File tree Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Expand file tree Collapse file tree 1 file changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -117,23 +117,35 @@ export class SSEClientTransport implements Transport {
117
117
}
118
118
119
119
private _startOrAuth ( ) : Promise < void > {
120
+ const fetchImpl = ( this ?. _eventSourceInit ?. fetch || fetch ) as typeof fetch
120
121
return new Promise ( ( resolve , reject ) => {
121
122
this . _eventSource = new EventSource (
122
123
this . _url . href ,
123
- this . _eventSourceInit ?? {
124
- fetch : ( url , init ) => this . _commonHeaders ( ) . then ( ( headers ) => fetch ( url , {
125
- ...init ,
126
- headers : {
127
- ...headers ,
128
- Accept : "text/event-stream"
124
+ {
125
+ ...this . _eventSourceInit ,
126
+ fetch : async ( url , init ) => {
127
+ const headers = await this . _commonHeaders ( )
128
+ const response = await fetchImpl ( url , {
129
+ ...init ,
130
+ headers : new Headers ( {
131
+ ...headers ,
132
+ Accept : "text/event-stream"
133
+ } )
134
+ } )
135
+
136
+ if ( response . status === 401 && response . headers . has ( 'www-authenticate' ) ) {
137
+ this . _resourceMetadataUrl = extractResourceMetadataUrl ( response ) ;
129
138
}
130
- } ) ) ,
139
+
140
+ return response
141
+ } ,
131
142
} ,
132
143
) ;
133
144
this . _abortController = new AbortController ( ) ;
134
145
135
146
this . _eventSource . onerror = ( event ) => {
136
147
if ( event . code === 401 && this . _authProvider ) {
148
+
137
149
this . _authThenStart ( ) . then ( resolve , reject ) ;
138
150
return ;
139
151
}
You can’t perform that action at this time.
0 commit comments