UNPKG

1.44 kBJavaScriptView Raw
1"use strict";
2var __importDefault = (this && this.__importDefault) || function (mod) {
3 return (mod && mod.__esModule) ? mod : { "default": mod };
4};
5Object.defineProperty(exports, "__esModule", { value: true });
6const Server_1 = require("../Server");
7const bytes_1 = __importDefault(require("bytes"));
8const debug_1 = require("../../debug");
9const AbstractMiddleware_1 = require("./AbstractMiddleware");
10const debug = debug_1.createDebugLogger('middleware:request');
11class RequestMiddleware extends AbstractMiddleware_1.AbstractMiddleware {
12 async pass(ctx, next) {
13 debug(`<-- ${ctx.method.toUpperCase()} ${ctx.path}`);
14 await next();
15 const response = ctx.state.response;
16 await response.patchContext(ctx);
17 // Head doesn't want a body. Hehe. I get why it's called head now.
18 // Raphaela seems to think that's not why they call it head. I'm filing for divorce.
19 // She looks sad now as she's reading along while I type this. For the record: I'm joking!
20 // No divorce.
21 // ...
22 // Yet.
23 // JK!
24 // Okay time to be productive again.
25 if (ctx.method === Server_1.RequestMethods.Head) {
26 delete ctx.body;
27 }
28 debug(`--> ${ctx.method.toUpperCase()} ${ctx.path} ${response.getStatusCode()} ${bytes_1.default(ctx.length)}`);
29 }
30}
31exports.RequestMiddleware = RequestMiddleware;
32//# sourceMappingURL=RequestMiddleware.js.map
\No newline at end of file