feat(server): Allow for custom HEAD method implementations (#1175)
Fixes https://github.com/denoland/fresh/issues/1115 Fixes https://github.com/denoland/fresh/issues/1165 --------- Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
co-authored by
Asher Gomez
parent
366c8afef1
commit
e86a126c0a
@@ -325,14 +325,9 @@ export class ServerContext {
|
||||
return Response.redirect(url.href, Status.TemporaryRedirect);
|
||||
}
|
||||
|
||||
// HEAD requests should be handled as GET requests but without the body.
|
||||
const originalMethod = req.method;
|
||||
// Internally, HEAD is handled in the same way as GET.
|
||||
if (req.method === "HEAD") {
|
||||
req = new Request(req.url, { method: "GET", headers: req.headers });
|
||||
}
|
||||
const res = await withMiddlewares(req, connInfo, inner);
|
||||
if (originalMethod === "HEAD") {
|
||||
// Internally, HEAD is handled in the same way as GET if not overridden.
|
||||
if (req.method === "HEAD") {
|
||||
res.body?.cancel();
|
||||
return new Response(null, {
|
||||
headers: res.headers,
|
||||
|
||||
@@ -157,6 +157,11 @@ export function router<T = unknown>(
|
||||
}
|
||||
}
|
||||
|
||||
// If not overridden, HEAD requests should be handled as GET requests but without the body.
|
||||
if (req.method === "HEAD" && !route.methods["HEAD"]) {
|
||||
req = new Request(req.url, { method: "GET", headers: req.headers });
|
||||
}
|
||||
|
||||
for (const [method, handler] of Object.entries(route.methods)) {
|
||||
if (req.method === method) {
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user