Skip to content

Commit

Permalink
reverting createRemixHeaders to previous fix for handling multiple co…
Browse files Browse the repository at this point in the history
…okies (#9664)

Co-authored-by: Matt Brophy <matt@brophy.org>
  • Loading branch information
Courey and brophdawg11 authored Jul 12, 2024
1 parent d58d4fb commit cb4dda0
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-planets-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/architect": patch
---

Manually joining headers with semi-colons to avoid differences in Remix and node/undici Headers implementation.
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
- colinhacks
- confix
- coryhouse
- courey
- courtyenn
- craigayre
- craigglennie
Expand Down
13 changes: 13 additions & 0 deletions packages/remix-architect/__tests__/server-test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fsp from "node:fs/promises";
import path from "node:path";
import { createRequestHandler as createRemixRequestHandler } from "@remix-run/node";
import { Headers as RemixHeaders } from "@remix-run/web-fetch";
import type { APIGatewayProxyEventV2 } from "aws-lambda";
import lambdaTester from "lambda-tester";

Expand Down Expand Up @@ -230,6 +231,18 @@ describe("architect createRemixHeaders", () => {
"__session=some_value; __other=some_other_value"
);
});

it("handles multiple request cookies when using @remix-run/web-fetch", () => {
let headers = createRemixHeaders(
{},
["__session=some_value", "__other=some_other_value"],
// @ts-expect-error types don't align since it's not fully spec compliant
RemixHeaders
);
expect(headers.get("cookie")).toEqual(
"__session=some_value; __other=some_other_value"
);
});
});
});

Expand Down
1 change: 1 addition & 0 deletions packages/remix-architect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"@architect/functions": "^5.2.0",
"@remix-run/node": "workspace:*",
"@remix-run/web-fetch": "^4.4.2",
"@types/aws-lambda": "^8.10.82"
},
"devDependencies": {
Expand Down
14 changes: 9 additions & 5 deletions packages/remix-architect/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ export function createRemixRequest(event: APIGatewayProxyEventV2): Request {

export function createRemixHeaders(
requestHeaders: APIGatewayProxyEventHeaders,
requestCookies?: string[]
requestCookies?: string[],
_Headers?: typeof Headers
): Headers {
let headers = new Headers();
// `_Headers` should only be used for unit testing purposes so we can unit test
// the different behaviors of the @remix-run/web-fetch `Headers` implementation
// and the node/undici implementation. See:
// https://github.com/remix-run/remix/issues/9657
let HeadersImpl = _Headers || Headers;
let headers = new HeadersImpl();

for (let [header, value] of Object.entries(requestHeaders)) {
if (value) {
Expand All @@ -88,9 +94,7 @@ export function createRemixHeaders(
}

if (requestCookies) {
for (let cookie of requestCookies) {
headers.append("Cookie", cookie);
}
headers.append("Cookie", requestCookies.join("; "));
}

return headers;
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cb4dda0

Please sign in to comment.