Skip to content

Commit 7b8bd8b

Browse files
committed
fix(json-rpc): do not set content-type header until we are sure we can use it
1 parent 1447b9f commit 7b8bd8b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/utils/json-rpc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,15 @@ export function defineJsonRpcHandler<RequestT extends EventHandlerRequest = Even
294294
// Filter out notifications (undefined responses) before returning.
295295
const finalResponses = responses.filter((r): r is JsonRpcResponse => r !== undefined);
296296

297-
event.res.headers.set("Content-Type", "application/json");
298-
299297
// Per spec §6, even when request is a batch, the server MUST NOT return an empty array.
300298
// If there are no responses to return (e.g. all notifications), return nothing.
301299
if (finalResponses.length === 0) {
302300
event.res.status = 202;
303301
return "";
304302
}
305303

304+
event.res.headers.set("Content-Type", "application/json");
305+
306306
// For a single request, return the single response object.
307307
// For a batch request, return the array of response objects.
308308
return isBatch ? finalResponses : finalResponses[0];

0 commit comments

Comments
 (0)