}
+ /**
+ * 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
];
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);
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);
const responseTypes = [...this.responseTypes, Enum.ContentType.ImageSVG];
- Dingus.setHeadHandler(req, res, ctx);
+ Service.setHeadHandler(req, res, ctx);
this.setResponseType(responseTypes, req, res, ctx);
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);
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);
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);
});
}); // maybeIngestBody
+ describe('setHeadHandler', function () {
+ it('covers', function () {
+ const origEnd = res.end;
+ sinon.stub(Service.__proto__, 'setHeadHandler');
+ ctx.responseBody = 'data';
+ req.method = 'HEAD';
+ Service.setHeadHandler(req, res, ctx);
+ res.end('foop');
+ assert(Service.__proto__.setHeadHandler.called);
+ assert(origEnd.called);
+ assert(!('responseBody' in ctx));
+ });
+ }); // setHeadHandler
+
describe('handlerPostRoot', function () {
it('covers public mode', async function () {
await service.handlerPostRoot(req, res, ctx);