"Small" Breaking Change
This release includes a "small" breaking change.
Before this release, if a HEAD
request was received, the app would handle it with the handler defined in app.head()
. If there were no preferred handlers, it would return "Not Found".
app.head('/foo', (c) => {
return new Response(null, {
headers: {
Foo: 'Bar',
},
})
})
This would handle:
HEAD /foo
Since this release, app.head()
will not be enabled. Instead, the app will automatically return the responses for HEAD
requests if it has a preferred app.get()
handler. This means you don't have to set the handlers for HEAD
explicitly.
const app = new Hono()
app.get('/', (c) => {
return c.text('Foo')
})
export default app
$ curl --head http://localhost:8787/
HTTP/1.1 200 OK
Content-Type: text/plain;charset=UTF-8
If you want to customize the response for HEAD
method, write like the following:
app.get('/', (c) => {
if (c.req.method === 'HEAD') {
return new Response(null, {
headers: {
'Content-Length': '12345',
},
})
}
return c.text('Foo')
})
You can still use app.head()
, but it will not have any effect. So, you should remove them.
What's Changed
- feat: define JSX.ElementChildrenAttribute interface by @yudai-nkt in #1139
- fix(reg-exp-router): Register static paths first for duplicate checking. by @usualoma in #1146
- ci: don't specify Bun version in CI by @yusukebe in #1149
- perf: use
indexOf()
intead ofincludes()
by @yusukebe in #1150 - feat: handle HEAD method by @yusukebe in #1142
- fix(tire-router/pattern-router): fixed the named capture issue by @yusukebe in #1148
- refactor: Tweaks variable names to reduce code. by @usualoma in #1157
Full Changelog: v3.2.3...v3.2.4