Skip to content

Commit 3730676

Browse files
authored
Match HEAD requests if the expected method is GET (#36)
2 parents ae46b44 + 45021a2 commit 3730676

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/routing/EndpointRoute.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export abstract class EndpointRoute implements Route {
1010
private readonly path: string;
1111

1212
/**
13-
* @param method The required HTTP method to match.
13+
* @param method The required HTTP method to match. If GET, will also match HEAD.
1414
* @param path The request URL path to match.
1515
*/
1616
protected constructor(method: Request.Method, path: string) {
@@ -19,7 +19,11 @@ export abstract class EndpointRoute implements Route {
1919
}
2020

2121
public match(req: Request): boolean {
22-
return req.method === this.method && req.url.pathname === this.path;
22+
return this.path === req.url.pathname
23+
&& (
24+
this.method === req.method
25+
|| (this.method === Request.Method.GET && req.method === Request.Method.HEAD)
26+
);
2327
}
2428

2529
public abstract handle(req: Request): Response | Promise<Response>;

0 commit comments

Comments
 (0)