import { HttpHandler } from "./router.ts";import { RoutingError } from "./error.ts";
export const methodFilter = (...method: string[]): HttpHandler => async req => { if (!method.includes(req.method)) { const u = new URL(req.url); throw new RoutingError(404, `Cannot ${req.method} ${u.pathname}`); }};
export const contentTypeFilter = ( ...types: (string | RegExp)[]): HttpHandler => async req => { if (types.some(v => req.headers.get("content-type").match(v) !== null)) { return; } throw new RoutingError(400, `Invalid content type`);};