Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions client/src/lib/hooks/useConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,22 @@ export function useConnection({
switch (transportType) {
case "sse":
requestHeaders["Accept"] = "text/event-stream";
requestHeaders["content-type"] = "application/json";
transportOptions = {
authProvider: serverAuthProvider,
fetch: async (
url: string | URL | globalThis.Request,
init?: RequestInit,
) => {
const mergedHeaders = { ...requestHeaders };
// Only set Content-Type on requests with a body (e.g. POST).
// GET requests (such as OAuth metadata discovery) must not
// include Content-Type, as some servers reject it with 415.
if (init?.body) {
mergedHeaders["content-type"] = "application/json";
}
const response = await fetch(url, {
...init,
headers: requestHeaders,
headers: mergedHeaders,
});

// Capture protocol-related headers from response
Expand All @@ -611,11 +617,16 @@ export function useConnection({
url: string | URL | globalThis.Request,
init?: RequestInit,
) => {
requestHeaders["Accept"] =
"text/event-stream, application/json";
requestHeaders["Content-Type"] = "application/json";
const mergedHeaders = { ...requestHeaders };
mergedHeaders["Accept"] = "text/event-stream, application/json";
// Only set Content-Type on requests with a body (e.g. POST).
// GET requests (such as OAuth metadata discovery) must not
// include Content-Type, as some servers reject it with 415.
if (init?.body) {
mergedHeaders["Content-Type"] = "application/json";
}
const response = await fetch(url, {
headers: requestHeaders,
headers: mergedHeaders,
...init,
});

Expand Down
Loading