Closed
Description
What version of Hono are you using?
4.7.5
What runtime/platform is your app running on? (with version if possible)
Cloudflare Workers
What steps can reproduce the bug?
-
run this hono app
import { Hono } from "hono"; import { trimTrailingSlash } from "hono/trailing-slash"; const app = new Hono(); app.use(trimTrailingSlash()); app.get("/", (c) => { return c.text("Hello Hono!"); }); app.get("/foo", (c) => { return c.text("Hello Foo!"); }); export default app;
-
try GET / HEAD request with trailing slash
❯ curl -sSfL http://localhost:8787/foo/ Hello Foo!% ❯ curl -sSfL -I http://localhost:8787/foo/ HTTP/1.1 404 Not Found Content-Type: text/plain; charset=UTF-8 curl: (22) The requested URL returned error: 404 # UNEXPECTED!
See this repository for reproduction: https://github.com/sushichan044/hono-trailing-slash-head
What is the expected behavior?
The hono application should handle HEAD requests, same as GET requests
What do you see instead?
In the case of a HEAD request, the trailing-slash middleware is not invoked, so a 404 will be returned only for HEAD requests.
Additional information
In Hono, the GET handler implicitly handles HEAD requests as well.
ref: #1142
However, since the trailingSlash middleware only handles GET requests, the GET and HEAD methods behave differently when accessing the same endpoint.