Skip to content

Commit

Permalink
fix: history-api-fallback now supports HEAD requests and handles them…
Browse files Browse the repository at this point in the history
… the same as GET
  • Loading branch information
awwit committed Jun 28, 2022
1 parent e0c4e7e commit 8936082
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 8 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -56,7 +56,7 @@
"chokidar": "^3.5.3",
"colorette": "^2.0.10",
"compression": "^1.7.4",
"connect-history-api-fallback": "^1.6.0",
"connect-history-api-fallback": "^2.0.0",
"default-gateway": "^6.0.3",
"express": "^4.17.3",
"graceful-fs": "^4.2.6",
Expand Down
Expand Up @@ -130,6 +130,15 @@ exports[`historyApiFallback option as object with the "verbose" option request t
"
`;

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"`;

exports[`historyApiFallback option in-memory files should perform HEAD request in same way as GET: response status 1`] = `"OK"`;

exports[`historyApiFallback option in-memory files should perform HEAD request in same way as GET: response text 1`] = `
"In-memory file
"
`;

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

exports[`historyApiFallback option in-memory files should take precedence over static files: page errors 1`] = `Array []`;
Expand Down
Expand Up @@ -130,6 +130,15 @@ exports[`historyApiFallback option as object with the "verbose" option request t
"
`;

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"`;

exports[`historyApiFallback option in-memory files should perform HEAD request in same way as GET: response status 1`] = `"OK"`;

exports[`historyApiFallback option in-memory files should perform HEAD request in same way as GET: response text 1`] = `
"In-memory file
"
`;

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

exports[`historyApiFallback option in-memory files should take precedence over static files: page errors 1`] = `Array []`;
Expand Down
40 changes: 40 additions & 0 deletions test/e2e/history-api-fallback.test.js
Expand Up @@ -643,5 +643,45 @@ describe("historyApiFallback option", () => {

expect(pageErrors).toMatchSnapshot("page errors");
});

it("should perform HEAD request in same way as GET", async () => {
await page.goto(`http://127.0.0.1:${port}/foo`, {
waitUntil: "networkidle0",
});

const responseGet = await page.evaluate(async () => {
const response = await fetch("/foo", { method: "GET" });

return {
contentType: response.headers.get("content-type"),
statusText: response.statusText,
text: await response.text(),
};
});

expect(responseGet.contentType).toMatchSnapshot(
"response headers content-type"
);

expect(responseGet.statusText).toMatchSnapshot("response status");

expect(responseGet.text).toMatchSnapshot("response text");

const responseHead = await page.evaluate(async () => {
const response = await fetch("/foo", { method: "HEAD" });

return {
contentType: response.headers.get("content-type"),
statusText: response.statusText,
text: await response.text(),
};
});

expect(responseHead).toMatchObject({
...responseGet,
// HEAD response has an empty body
text: "",
});
});
});
});

0 comments on commit 8936082

Please sign in to comment.