import { ContextInterface } from '../Interface' ; import { Response } from '../Response' ; import { RequestMethods } from '../Server' ; import bytes from 'bytes' ; import { createDebugLogger } from '../../debug' ; import { AbstractMiddleware } from './AbstractMiddleware' ; const debug = createDebugLogger ( 'middleware:request' ) ; export class RequestMiddleware extends AbstractMiddleware { public async pass ( ctx , next ) { debug ( `<-- ${ ctx . method . toUpperCase ( ) } ${ ctx . path }` ) ; await next ( ) ; const response = ctx . state . response ; await response . patchContext ( ctx ) ; if ( ctx . method === RequestMethods . Head ) { delete ctx . body ; } debug ( `--> ${ ctx . method . toUpperCase ( ) } ${ ctx . path } ${ response . getStatusCode ( ) } ${ bytes ( ctx . length ) }` ) ; } }