diff options
Diffstat (limited to 'packages/taler-util/src/http-common.ts')
-rw-r--r-- | packages/taler-util/src/http-common.ts | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts index 54f26e615..e5dd92567 100644 --- a/packages/taler-util/src/http-common.ts +++ b/packages/taler-util/src/http-common.ts @@ -59,7 +59,7 @@ export interface HttpRequestOptions { */ cancellationToken?: CancellationToken; - body?: string | ArrayBuffer | Record<string, unknown>; + body?: string | ArrayBuffer | object; } /** @@ -344,9 +344,8 @@ export function getExpiry( return t; } - export interface HttpLibArgs { - enableThrottling?: boolean, + enableThrottling?: boolean; } export function encodeBody(body: any): ArrayBuffer { @@ -364,3 +363,16 @@ export function encodeBody(body: any): ArrayBuffer { } throw new TypeError("unsupported request body type"); } + +export function getDefaultHeaders(method: string): Record<string, string> { + const headers: Record<string, string> = {}; + + if (method === "POST" || method === "PUT" || method === "PATCH") { + // Default to JSON if we have a body + headers["Content-Type"] = "application/json"; + } + + headers["Accept"] = "application/json"; + + return headers; +} |