fix: HEAD method not handled properly (#3563)

- It should never contain a response body
- It should be equivalent to `GET`
This commit is contained in:
Marvin Hagemeister
2025-10-21 15:43:17 +02:00
committed by GitHub
parent de1810e70d
commit 41b9422dd1
4 changed files with 91 additions and 8 deletions
+9 -2
View File
@@ -120,7 +120,10 @@ export class UrlPatternRouter<T> implements Router<T> {
if (staticMatch !== undefined) {
result.pattern = url.pathname;
const handlers = staticMatch.byMethod[method];
let handlers = staticMatch.byMethod[method];
if (method === "HEAD" && handlers.length === 0) {
handlers = staticMatch.byMethod.GET;
}
if (handlers.length > 0) {
result.methodMatch = true;
result.handlers.push(...handlers);
@@ -137,7 +140,11 @@ export class UrlPatternRouter<T> implements Router<T> {
result.pattern = route.pattern.pathname;
const handlers = route.byMethod[method];
let handlers = route.byMethod[method];
if (method === "HEAD" && handlers.length === 0) {
handlers = route.byMethod.GET;
}
if (handlers.length > 0) {
result.methodMatch = true;
result.handlers.push(...handlers);