Skip to content

Commit 03acb1a

Browse files
committed
fix(apns): cancel redirect relay response body before returning
1 parent f80c4b9 commit 03acb1a

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎src/infra/push-apns.relay.test.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,20 @@ describe("push-apns.relay", () => {
285285
expect(result.environment).toBeUndefined();
286286
});
287287

288+
it("cancels a redirect relay response body before returning", async () => {
289+
const response = new Response("redirected", { status: 307 });
290+
const cancel = vi.spyOn(response.body!, "cancel").mockResolvedValue(undefined);
291+
const fetchMock = vi.fn().mockResolvedValue(response);
292+
vi.stubGlobal("fetch", fetchMock as unknown as typeof fetch);
293+
294+
const result = await sendApnsRelayPush(createRelayPushParams());
295+
296+
expect(result.ok).toBe(false);
297+
expect(result.status).toBe(307);
298+
expect(result.reason).toBe("RelayRedirectNotAllowed");
299+
expect(cancel).toHaveBeenCalledOnce();
300+
});
301+
288302
it("falls back to fetch status when the relay body is not JSON", async () => {
289303
// Real Response body so the bounded reader runs end-to-end; non-JSON parse stays a soft null.
290304
const fetchMock = vi.fn().mockResolvedValue(new Response("not-json-at-all", { status: 202 }));

‎src/infra/push-apns.relay.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ async function sendApnsRelayRequest(params: {
295295
});
296296
// Do not follow relay redirects; grants and signatures are scoped to the configured relay origin.
297297
if (response.status >= 300 && response.status < 400) {
298+
await response.body?.cancel().catch(() => undefined);
298299
return {
299300
ok: false,
300301
status: response.status,

0 commit comments

Comments
 (0)