fix: extra Headers when they are a Headers object

This commit is contained in:
Diego García 2025-05-30 16:05:05 +02:00
commit be063e4bb8
No known key found for this signature in database
GPG key ID: D7671B49990E0037

View file

@ -476,6 +476,37 @@ describe("StreamableHTTPClientTransport", () => {
expect(global.fetch).toHaveBeenCalledTimes(2);
});
it("should always send specified custom headers (Headers class)", async () => {
const requestInit = {
headers: new Headers({
"X-Custom-Header": "CustomValue"
})
};
transport = new StreamableHTTPClientTransport(new URL("http://localhost:1234/mcp"), {
requestInit: requestInit
});
let actualReqInit: RequestInit = {};
((global.fetch as jest.Mock)).mockImplementation(
async (_url, reqInit) => {
actualReqInit = reqInit;
return new Response(null, { status: 200, headers: { "content-type": "text/event-stream" } });
}
);
await transport.start();
await transport["_startOrAuthSse"]({});
expect((actualReqInit.headers as Headers).get("x-custom-header")).toBe("CustomValue");
(requestInit.headers as Headers).set("X-Custom-Header","SecondCustomValue");
await transport.send({ jsonrpc: "2.0", method: "test", params: {} } as JSONRPCMessage);
expect((actualReqInit.headers as Headers).get("x-custom-header")).toBe("SecondCustomValue");
expect(global.fetch).toHaveBeenCalledTimes(2);
});
it("should have exponential backoff with configurable maxRetries", () => {
// This test verifies the maxRetries and backoff calculation directly