Skip to content

Commit 8936082

Browse files
authored
fix: history-api-fallback now supports HEAD requests and handles them the same as GET
1 parent e0c4e7e commit 8936082

File tree

5 files changed

+66
-8
lines changed

5 files changed

+66
-8
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"chokidar": "^3.5.3",
5757
"colorette": "^2.0.10",
5858
"compression": "^1.7.4",
59-
"connect-history-api-fallback": "^1.6.0",
59+
"connect-history-api-fallback": "^2.0.0",
6060
"default-gateway": "^6.0.3",
6161
"express": "^4.17.3",
6262
"graceful-fs": "^4.2.6",

test/e2e/__snapshots__/history-api-fallback.test.js.snap.webpack4

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ exports[`historyApiFallback option as object with the "verbose" option request t
130130
"
131131
`;
132132

133+
exports[`historyApiFallback option in-memory files should perform HEAD request in same way as GET: response headers content-type 1`] = `"text/html; charset=utf-8"`;
134+
135+
exports[`historyApiFallback option in-memory files should perform HEAD request in same way as GET: response status 1`] = `"OK"`;
136+
137+
exports[`historyApiFallback option in-memory files should perform HEAD request in same way as GET: response text 1`] = `
138+
"In-memory file
139+
"
140+
`;
141+
133142
exports[`historyApiFallback option in-memory files should take precedence over static files: console messages 1`] = `Array []`;
134143

135144
exports[`historyApiFallback option in-memory files should take precedence over static files: page errors 1`] = `Array []`;

test/e2e/__snapshots__/history-api-fallback.test.js.snap.webpack5

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ exports[`historyApiFallback option as object with the "verbose" option request t
130130
"
131131
`;
132132

133+
exports[`historyApiFallback option in-memory files should perform HEAD request in same way as GET: response headers content-type 1`] = `"text/html; charset=utf-8"`;
134+
135+
exports[`historyApiFallback option in-memory files should perform HEAD request in same way as GET: response status 1`] = `"OK"`;
136+
137+
exports[`historyApiFallback option in-memory files should perform HEAD request in same way as GET: response text 1`] = `
138+
"In-memory file
139+
"
140+
`;
141+
133142
exports[`historyApiFallback option in-memory files should take precedence over static files: console messages 1`] = `Array []`;
134143

135144
exports[`historyApiFallback option in-memory files should take precedence over static files: page errors 1`] = `Array []`;

test/e2e/history-api-fallback.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,5 +643,45 @@ describe("historyApiFallback option", () => {
643643

644644
expect(pageErrors).toMatchSnapshot("page errors");
645645
});
646+
647+
it("should perform HEAD request in same way as GET", async () => {
648+
await page.goto(`http://127.0.0.1:${port}/foo`, {
649+
waitUntil: "networkidle0",
650+
});
651+
652+
const responseGet = await page.evaluate(async () => {
653+
const response = await fetch("/foo", { method: "GET" });
654+
655+
return {
656+
contentType: response.headers.get("content-type"),
657+
statusText: response.statusText,
658+
text: await response.text(),
659+
};
660+
});
661+
662+
expect(responseGet.contentType).toMatchSnapshot(
663+
"response headers content-type"
664+
);
665+
666+
expect(responseGet.statusText).toMatchSnapshot("response status");
667+
668+
expect(responseGet.text).toMatchSnapshot("response text");
669+
670+
const responseHead = await page.evaluate(async () => {
671+
const response = await fetch("/foo", { method: "HEAD" });
672+
673+
return {
674+
contentType: response.headers.get("content-type"),
675+
statusText: response.statusText,
676+
text: await response.text(),
677+
};
678+
});
679+
680+
expect(responseHead).toMatchObject({
681+
...responseGet,
682+
// HEAD response has an empty body
683+
text: "",
684+
});
685+
});
646686
});
647687
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy