Skip to content

Commit b50a62f

Browse files
author
Charlie Tonneslan
committed
fix: preserve custom Accept headers instead of unconditionally overwriting
The SDK unconditionally overwrites Accept headers with headers.set(), discarding any custom Accept values provided via requestInit.headers. This breaks APIs that require specific Accept header values. Now checks headers.has('Accept') before setting the default value, preserving user-provided Accept headers in both Streamable HTTP and SSE transports. Fixes #1646
1 parent ccb78f2 commit b50a62f

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

packages/client/src/client/sse.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ export class SSEClientTransport implements Transport {
143143
...this._eventSourceInit,
144144
fetch: async (url, init) => {
145145
const headers = await this._commonHeaders();
146-
headers.set('Accept', 'text/event-stream');
146+
if (!headers.has('Accept')) {
147+
headers.set('Accept', 'text/event-stream');
148+
}
147149
const response = await fetchImpl(url, {
148150
...init,
149151
headers

packages/client/src/client/streamableHttp.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ export class StreamableHTTPClientTransport implements Transport {
214214
// Try to open an initial SSE stream with GET to listen for server messages
215215
// This is optional according to the spec - server may not support it
216216
const headers = await this._commonHeaders();
217-
headers.set('Accept', 'text/event-stream');
217+
if (!headers.has('Accept')) {
218+
headers.set('Accept', 'text/event-stream');
219+
}
218220

219221
// Include Last-Event-ID header for resumable streams if provided
220222
if (resumptionToken) {
@@ -473,7 +475,9 @@ export class StreamableHTTPClientTransport implements Transport {
473475

474476
const headers = await this._commonHeaders();
475477
headers.set('content-type', 'application/json');
476-
headers.set('accept', 'application/json, text/event-stream');
478+
if (!headers.has('accept')) {
479+
headers.set('accept', 'application/json, text/event-stream');
480+
}
477481

478482
const init = {
479483
...this._requestInit,

0 commit comments

Comments
 (0)