From 3fe172a1333dd504315e5a2887358a63c1a16e2a Mon Sep 17 00:00:00 2001 From: Chris Wilkinson Date: Fri, 17 Jan 2025 15:23:23 +0000 Subject: [PATCH] Fix following relative locations --- .changeset/tiny-onions-change.md | 5 +++++ packages/platform/src/internal/httpClient.ts | 2 +- packages/platform/test/HttpClient.test.ts | 16 ++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changeset/tiny-onions-change.md diff --git a/.changeset/tiny-onions-change.md b/.changeset/tiny-onions-change.md new file mode 100644 index 00000000000..02e2ac7f675 --- /dev/null +++ b/.changeset/tiny-onions-change.md @@ -0,0 +1,5 @@ +--- +"@effect/platform": patch +--- + +Fix following relative locations diff --git a/packages/platform/src/internal/httpClient.ts b/packages/platform/src/internal/httpClient.ts index f6c0f9b2342..1181d29c38c 100644 --- a/packages/platform/src/internal/httpClient.ts +++ b/packages/platform/src/internal/httpClient.ts @@ -711,7 +711,7 @@ export const followRedirects = dual< ? loop( internalRequest.setUrl( request, - response.headers.location + new URL(response.headers.location, response.request.url) ), redirects + 1 ) diff --git a/packages/platform/test/HttpClient.test.ts b/packages/platform/test/HttpClient.test.ts index a3adc1f94e0..2716241b5ef 100644 --- a/packages/platform/test/HttpClient.test.ts +++ b/packages/platform/test/HttpClient.test.ts @@ -221,4 +221,20 @@ describe("HttpClient", () => { body: { _id: "@effect/platform/HttpBody", _tag: "Empty" } }) }) + + it("followRedirects", () => + Effect.gen(function*(_) { + const defaultClient = yield* HttpClient.HttpClient + const client = defaultClient.pipe(HttpClient.followRedirects()) + + const response = yield* _( + client.get("https://google.com/"), + Effect.scoped + ) + expect(response.request.url).toBe("https://www.google.com/") + }).pipe( + Effect.provide(FetchHttpClient.layer), + Effect.provideService(FetchHttpClient.RequestInit, { redirect: "manual" }), + Effect.runPromise + )) })