| 10 | * @param allowedMethods - Methods this command declares, for the `Allow` header on `HEAD` |
| 11 | */ |
| 12 | export function unknownMethodHandler(allowedMethods: string): RequestHandler { |
| 13 | return function rejectUnknownMethod(req: Request, res: Response): void { |
| 14 | if (req.method === 'HEAD') { |
| 15 | res.status(405).set('Allow', allowedMethods).set('Content-Type', 'application/json; charset=utf-8').end(); |
| 16 | return; |
| 17 | } |
| 18 | log.debug(`Method ${req.method} is not supported for ${req.path}`); |
| 19 | const [status, body] = getResponseForW3CError(new errors.UnknownMethodError()); |
| 20 | res.status(status).json(body); |
| 21 | }; |
| 22 | } |