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
Show file tree
Hide file tree
Changes from 7 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
Expand Up @@ -114,6 +114,7 @@
- colinhacks
- confix
- coryhouse
- courey
- courtyenn
- craigayre
- craigglennie
Expand Down
12 changes: 12 additions & 0 deletions packages/remix-architect/__tests__/server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from "node:path";
import { createRequestHandler as createRemixRequestHandler } from "@remix-run/node";
import type { APIGatewayProxyEventV2 } from "aws-lambda";
import lambdaTester from "lambda-tester";
import { Headers as RemixHeaders } from "@remix-run/web-fetch";
brophdawg11 marked this conversation as resolved.
Show resolved Hide resolved

import {
createRequestHandler,
Expand Down Expand Up @@ -230,6 +231,17 @@ 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
brophdawg11 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading
Loading