X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=src%2Fservice.js;h=17fa134d738447deb29aa5e889aaf806cb1443f8;hb=17b4ff9c1974842c02071d2cd02144d2e5a99eb5;hp=d493f8affdf83f3585973ad380c3f9a5ab8caa48;hpb=06565fb4b802c38a60d4c6e0f4b65c26da18d69f;p=websub-hub diff --git a/src/service.js b/src/service.js index d493f8a..17fa134 100644 --- a/src/service.js +++ b/src/service.js @@ -68,6 +68,24 @@ class Service extends Dingus { } + /** + * Wrap the Dingus head handler, to remove the response body from the context, + * lest it be logged. + * @param {http.ClientRequest} req + * @param {http.ServerResponse} res + * @param {object} ctx + */ + static setHeadHandler(req, res, ctx) { + if (req.method === 'HEAD') { + Dingus.setHeadHandler(req, res, ctx); + const origEnd = res.end.bind(res); + res.end = function (data, encoding, ...rest) { + const origResult = origEnd(data, encoding, ...rest); + delete ctx.responseBody; + return origResult; + }; + } + } /** * @param {http.ClientRequest} req @@ -97,7 +115,7 @@ class Service extends Dingus { ]; this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); - Dingus.setHeadHandler(req, res, ctx); + Service.setHeadHandler(req, res, ctx); this.setResponseType(responseTypes, req, res, ctx); @@ -116,7 +134,7 @@ class Service extends Dingus { const _scope = _fileScope('handlerGetHealthcheck'); this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); - Dingus.setHeadHandler(req, res, ctx); + Service.setHeadHandler(req, res, ctx); this.setResponseType(this.responseTypes, req, res, ctx); @@ -135,7 +153,7 @@ class Service extends Dingus { const responseTypes = [...this.responseTypes, Enum.ContentType.ImageSVG]; - Dingus.setHeadHandler(req, res, ctx); + Service.setHeadHandler(req, res, ctx); this.setResponseType(responseTypes, req, res, ctx); @@ -152,7 +170,7 @@ class Service extends Dingus { const _scope = _fileScope('handlerGetAdminOverview'); this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); - Dingus.setHeadHandler(req, res, ctx); + Service.setHeadHandler(req, res, ctx); this.setResponseType(this.responseTypes, req, res, ctx); @@ -171,7 +189,7 @@ class Service extends Dingus { const _scope = _fileScope('handlerGetAdminTopicDetails'); this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); - Dingus.setHeadHandler(req, res, ctx); + Service.setHeadHandler(req, res, ctx); this.setResponseType(this.responseTypes, req, res, ctx); @@ -264,7 +282,7 @@ class Service extends Dingus { const _scope = _fileScope('handlerGetAdminLogin'); this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx }); - Dingus.setHeadHandler(req, res, ctx); + Service.setHeadHandler(req, res, ctx); this.setResponseType(this.responseTypes, req, res, ctx);