Skip to content

Commit 1b3874e

Browse files
committed
refactor: simplify the code + update javadoc
1 parent 056ce81 commit 1b3874e

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/client/sse.ts

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ export type SSEClientTransportOptions = {
3535

3636
/**
3737
* Customizes the initial SSE request to the server (the request that begins the stream).
38-
*
39-
* NOTE: Setting this property will prevent an `Authorization` header from
40-
* being automatically attached to the SSE request, if an `authProvider` is
41-
* also given. This can be worked around by setting the `Authorization` header
42-
* manually.
4338
*/
4439
eventSourceInit?: EventSourceInit;
4540

@@ -64,7 +59,7 @@ export class SSEClientTransport implements Transport {
6459
private _abortController?: AbortController;
6560
private _url: URL;
6661
private _resourceMetadataUrl?: URL;
67-
private _eventSourceInit: EventSourceInit;
62+
private _eventSourceInit?: EventSourceInit;
6863
private _requestInit?: RequestInit;
6964
private _authProvider?: OAuthClientProvider;
7065
private _fetch?: FetchLike;
@@ -80,19 +75,7 @@ export class SSEClientTransport implements Transport {
8075
) {
8176
this._url = url;
8277
this._resourceMetadataUrl = undefined;
83-
84-
const actualFetch = opts?.eventSourceInit?.fetch ?? opts?.fetch ?? fetch;
85-
this._eventSourceInit = {
86-
...(opts?.eventSourceInit ?? {}),
87-
fetch: (url, init) => this._commonHeaders().then((headers) => actualFetch(url, {
88-
...init,
89-
headers: {
90-
...Object.fromEntries(headers.entries()),
91-
Accept: "text/event-stream"
92-
}
93-
})),
94-
};
95-
78+
this._eventSourceInit = opts?.eventSourceInit;
9679
this._requestInit = opts?.requestInit;
9780
this._authProvider = opts?.authProvider;
9881
this._fetch = opts?.fetch;
@@ -147,7 +130,9 @@ export class SSEClientTransport implements Transport {
147130
headers.set("Accept", "text/event-stream");
148131
const response = await fetchImpl(url, {
149132
...init,
150-
headers,
133+
headers: {
134+
...Object.fromEntries(headers.entries()),
135+
}
151136
})
152137

153138
if (response.status === 401 && response.headers.has('www-authenticate')) {

0 commit comments

Comments
 (0)