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

fix: change how request is "cloned" for loaders #3218

Merged
merged 2 commits into from
May 17, 2022
Merged
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions packages/remix-server-runtime/__tests__/handler-test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { json } from "../responses";
import { createRequestHandler } from "../server";

describe("createRequestHandler", () => {
it("retains request headers when stripping body off for loaders", async () => {
let handler = createRequestHandler({
routes: {
root: {
id: "routes/test",
path: "/test",
module: {
loader: ({ request }) => json(request.headers.get("X-Foo")),
} as any,
},
},
assets: {} as any,
entry: { module: {} as any },
});

let response = await handler(
new Request("http://.../test", {
headers: {
"X-Foo": "bar",
},
})
);

expect(await response.json()).toBe("bar");
});
});
5 changes: 4 additions & 1 deletion packages/remix-server-runtime/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,11 @@ async function handleDocumentRequest({
}

let loaderRequest = new Request(request.url, {
...request,
body: null,
headers: request.headers,
method: request.method,
redirect: request.redirect,
signal: request.signal,
});

let routeLoaderResults = await Promise.allSettled(
Expand Down