diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts | 11 | ||||
-rw-r--r-- | packages/taler-util/src/http-common.ts | 8 | ||||
-rw-r--r-- | packages/taler-util/src/http-impl.node.ts | 5 |
3 files changed, 17 insertions, 7 deletions
diff --git a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts index 21e2b4a4e..8e664dfa9 100644 --- a/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts +++ b/packages/taler-harness/src/integrationtests/test-merchant-spec-public-orders.ts @@ -297,8 +297,11 @@ async function testWithClaimToken( url.searchParams.set("session_id", sessionId); const httpResp = await httpLib.fetch(url.href, { headers: { Accept: "text/html" }, + redirect: "manual", }); - console.log(`requesting GET ${url.href}, expected 302 got ${httpResp.status}`); + console.log( + `requesting GET ${url.href}, expected 302 got ${httpResp.status}`, + ); t.assertDeepEqual(httpResp.status, 302); const location = httpResp.headers.get("Location"); console.log("location header:", location); @@ -554,6 +557,7 @@ async function testWithoutClaimToken( url.searchParams.set("session_id", sessionId); const httpResp = await httpLib.fetch(url.href, { headers: { Accept: "text/html" }, + redirect: "manual", }); t.assertDeepEqual(httpResp.status, 302); const location = httpResp.headers.get("Location"); @@ -569,9 +573,8 @@ async function testWithoutClaimToken( * specification of the endpoint. */ export async function runMerchantSpecPublicOrdersTest(t: GlobalTestState) { - const { bank, exchange, merchant } = await createSimpleTestkudosEnvironmentV2( - t, - ); + const { bank, exchange, merchant } = + await createSimpleTestkudosEnvironmentV2(t); // Base URL for the default instance. const merchantBaseUrl = merchant.makeInstanceBaseUrl(); diff --git a/packages/taler-util/src/http-common.ts b/packages/taler-util/src/http-common.ts index 705881801..3973e66fb 100644 --- a/packages/taler-util/src/http-common.ts +++ b/packages/taler-util/src/http-common.ts @@ -27,7 +27,7 @@ import { } from "./index.js"; import { Logger } from "./logging.js"; import { TalerErrorCode } from "./taler-error-codes.js"; -import { Duration, AbsoluteTime } from "./time.js"; +import { AbsoluteTime, Duration } from "./time.js"; import { TalerErrorDetail } from "./wallet-types.js"; const textEncoder = new TextEncoder(); @@ -65,6 +65,12 @@ export interface HttpRequestOptions { cancellationToken?: CancellationToken; body?: string | ArrayBuffer | object; + + /** + * How to handle redirects. + * Same semantics as WHATWG fetch. + */ + redirect?: "follow" | "error" | "manual"; } /** diff --git a/packages/taler-util/src/http-impl.node.ts b/packages/taler-util/src/http-impl.node.ts index b9c007b35..8ca2deecd 100644 --- a/packages/taler-util/src/http-impl.node.ts +++ b/packages/taler-util/src/http-impl.node.ts @@ -21,7 +21,7 @@ */ import * as net from "node:net"; import type { ClientRequest, IncomingMessage } from "node:http"; -import { RedirectableRequest, http, https } from "follow-redirects"; +import { FollowOptions, RedirectableRequest, http, https } from "follow-redirects"; import { RequestOptions } from "node:http"; import { TalerError } from "./errors.js"; import { encodeBody, getDefaultHeaders, HttpLibArgs } from "./http-common.js"; @@ -141,7 +141,7 @@ export class HttpLibImpl implements HttpRequestLibrary { throw Error(`unsupported protocol (${parsedUrl.protocol})`); } - const options: RequestOptions = { + const options: RequestOptions & FollowOptions<RequestOptions> = { protocol, port: parsedUrl.port, host: parsedUrl.hostname, @@ -149,6 +149,7 @@ export class HttpLibImpl implements HttpRequestLibrary { path, headers: requestHeadersMap, timeout: timeoutMs, + followRedirects: opt?.redirect !== "manual", }; const chunks: Uint8Array[] = []; |