Skip to content

Commit 3e6f856

Browse files
fix(mobile): tolerate native Headers without getSetCookie (#10851)
Co-authored-by: Ryan Hughes <[email protected]>
1 parent 9d6c43f commit 3e6f856

3 files changed

Lines changed: 172 additions & 133 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { describe, expect, it } from "vite-plus/test";
2+
import { Cookies, HttpClientRequest, HttpClientResponse } from "effect/unstable/http";
3+
4+
describe("React Native HTTP responses", () => {
5+
it("can inspect a rejected response when native Headers has no getSetCookie", () => {
6+
const response = new Response("Registration rejected", { status: 400 });
7+
Object.defineProperty(response.headers, "getSetCookie", { value: undefined });
8+
const result = HttpClientResponse.fromWeb(
9+
HttpClientRequest.post("https://relay.example.test/v1/mobile/devices"),
10+
response,
11+
);
12+
expect(result.cookies).toEqual(Cookies.empty);
13+
expect(result.status).toBe(400);
14+
});
15+
16+
it("preserves cookies on platforms that expose Set-Cookie headers", () => {
17+
const result = HttpClientResponse.fromWeb(
18+
HttpClientRequest.get("https://relay.example.test"),
19+
new Response(null, { headers: { "Set-Cookie": "session=abc; HttpOnly" } }),
20+
);
21+
expect(result.cookies).toEqual(Cookies.fromSetCookie(["session=abc; HttpOnly"]));
22+
});
23+
});

‎patches/[email protected]‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,19 @@ index ec78917..342f9d7 100644
324324
/**
325325
* Represents optional client protocol hooks that run when a transport connects
326326
* and disconnects.
327+
diff --git a/dist/unstable/http/HttpClientResponse.js b/dist/unstable/http/HttpClientResponse.js
328+
--- a/dist/unstable/http/HttpClientResponse.js
329+
+++ b/dist/unstable/http/HttpClientResponse.js
330+
@@ -177,3 +177,3 @@
331+
}
332+
- return this.cachedCookies = Cookies.fromSetCookie(this.source.headers.getSetCookie());
333+
+ return this.cachedCookies = Cookies.fromSetCookie(this.source.headers.getSetCookie?.() ?? []);
334+
}
335+
diff --git a/src/unstable/http/HttpClientResponse.ts b/src/unstable/http/HttpClientResponse.ts
336+
--- a/src/unstable/http/HttpClientResponse.ts
337+
+++ b/src/unstable/http/HttpClientResponse.ts
338+
@@ -309,3 +309,3 @@
339+
}
340+
- return this.cachedCookies = Cookies.fromSetCookie(this.source.headers.getSetCookie())
341+
+ return this.cachedCookies = Cookies.fromSetCookie(this.source.headers.getSetCookie?.() ?? [])
342+
}

0 commit comments

Comments
 (0)