Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reverting createRemixHeaders to previous fix for handling multiple cookies #9664

Merged
merged 9 commits into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -114,6 +114,7 @@
- colinhacks
- confix
- coryhouse
- courey
- courtyenn
- craigayre
- craigglennie
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";

@@ -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", () => {
brophdawg11 marked this conversation as resolved.
Show resolved Hide resolved
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"
);
});
});
});

1 change: 1 addition & 0 deletions packages/remix-architect/package.json
Original file line number Diff line number Diff line change
@@ -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": {
14 changes: 9 additions & 5 deletions packages/remix-architect/server.ts
Original file line number Diff line number Diff line change
@@ -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) {
@@ -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;
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.