diff options
Diffstat (limited to 'packages/taler-util/src/http-impl.qtart.ts')
-rw-r--r-- | packages/taler-util/src/http-impl.qtart.ts | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/packages/taler-util/src/http-impl.qtart.ts b/packages/taler-util/src/http-impl.qtart.ts index 954b41802..ee3d1f725 100644 --- a/packages/taler-util/src/http-impl.qtart.ts +++ b/packages/taler-util/src/http-impl.qtart.ts @@ -21,7 +21,7 @@ */ import { Logger } from "@gnu-taler/taler-util"; import { TalerError } from "./errors.js"; -import { encodeBody, HttpLibArgs } from "./http-common.js"; +import { encodeBody, getDefaultHeaders, HttpLibArgs } from "./http-common.js"; import { Headers, HttpRequestLibrary, @@ -54,7 +54,7 @@ export class HttpLibImpl implements HttpRequestLibrary { } async fetch(url: string, opt?: HttpRequestOptions): Promise<HttpResponse> { - const method = opt?.method ?? "GET"; + const method = (opt?.method ?? "GET").toUpperCase(); logger.trace(`Requesting ${method} ${url}`); @@ -72,19 +72,18 @@ export class HttpLibImpl implements HttpRequestLibrary { } let data: ArrayBuffer | undefined = undefined; - let headers: string[] = []; - if (opt?.headers) { - for (let headerName of Object.keys(opt.headers)) { - headers.push(`${headerName}: ${opt.headers[headerName]}`); - } + const requestHeadersMap = { ...getDefaultHeaders(method), ...opt?.headers }; + let headersList: string[] = []; + for (let headerName of Object.keys(requestHeadersMap)) { + headersList.push(`${headerName}: ${requestHeadersMap[headerName]}`); } - if (method.toUpperCase() === "POST") { + if (method === "POST") { data = encodeBody(opt?.body); } const res = await qjsOs.fetchHttp(url, { method, data, - headers, + headers: headersList, }); return { requestMethod: method, |