From 4e4ba75cc0d4ae890855cadb03c2d3d1b91f1e8f Mon Sep 17 00:00:00 2001 From: Niels Bosman Date: Wed, 3 Jan 2024 16:51:08 +0100 Subject: [PATCH] chore: add content type json default headers --- src/utils/streams.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/utils/streams.ts b/src/utils/streams.ts index bce2188..109f400 100644 --- a/src/utils/streams.ts +++ b/src/utils/streams.ts @@ -3,6 +3,10 @@ import type { UseChatStreamOptions } from '../hooks/useChatStream'; +const DEFAULT_HEADERS = { + 'Content-Type': 'application/json', +}; + const mergeInputInOptions = (input: string, options: UseChatStreamOptions, method: UseChatStreamInputMethod) => { options.query = options.query ?? {}; (options[method.type] as Record)[method.key] = input; @@ -18,7 +22,10 @@ export const getStream = async (input: string, options: UseChatStreamOptions, me const response = await fetch(options.url + params, { method: options.method, - headers: options.headers, + headers: { + ...DEFAULT_HEADERS, + ...options.headers + }, body: JSON.stringify(options.body, (_k, v) => v === null ? undefined : v) });