update api-dingus dependency
[websub-hub] / src / service.js
index df894011dc84f7cad424467b9e62720d4890f9d4..cfed60c5660ddd1b1a9f2691cd64ee77c7048d17 100644 (file)
@@ -69,24 +69,6 @@ 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
@@ -116,7 +98,7 @@ class Service extends Dingus {
     ];
     this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx });
 
-    Service.setHeadHandler(req, res, ctx);
+    Dingus.setHeadHandler(req, res, ctx);
 
     this.setResponseType(responseTypes, req, res, ctx);
 
@@ -135,7 +117,7 @@ class Service extends Dingus {
     const _scope = _fileScope('handlerGetHealthcheck');
     this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx });
   
-    Service.setHeadHandler(req, res, ctx);
+    Dingus.setHeadHandler(req, res, ctx);
 
     this.setResponseType(this.responseTypes, req, res, ctx);
 
@@ -154,7 +136,7 @@ class Service extends Dingus {
 
     const responseTypes = [...this.responseTypes, Enum.ContentType.ImageSVG];
 
-    Service.setHeadHandler(req, res, ctx);
+    Dingus.setHeadHandler(req, res, ctx);
 
     this.setResponseType(responseTypes, req, res, ctx);
 
@@ -168,7 +150,7 @@ class Service extends Dingus {
 
     const responseTypes = [Enum.ContentType.ImageSVG];
 
-    Service.setHeadHandler(req, res, ctx);
+    Dingus.setHeadHandler(req, res, ctx);
 
     this.setResponseType(responseTypes, req, res, ctx);
 
@@ -185,7 +167,7 @@ class Service extends Dingus {
     const _scope = _fileScope('handlerGetAdminOverview');
     this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx });
 
-    Service.setHeadHandler(req, res, ctx);
+    Dingus.setHeadHandler(req, res, ctx);
 
     this.setResponseType(this.responseTypes, req, res, ctx);
 
@@ -204,7 +186,7 @@ class Service extends Dingus {
     const _scope = _fileScope('handlerGetAdminTopicDetails');
     this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx });
 
-    Service.setHeadHandler(req, res, ctx);
+    Dingus.setHeadHandler(req, res, ctx);
 
     this.setResponseType(this.responseTypes, req, res, ctx);
 
@@ -215,20 +197,15 @@ class Service extends Dingus {
 
 
   /**
-   * Similar to super.ingestBody, but if no body was sent, do not parse (and
-   * thus avoid possible unsupported media type error).
-   * Also removes raw body from context, to simplify scrubbing sensitive data from logs.
+   * If no body was sent, do not parse (and thus avoid possible unsupported media type error).
    * @param {http.ClientRequest} req
    * @param {http.ServerResponse} res
    * @param {Object} ctx
    */
   async maybeIngestBody(req, res, ctx) {
-    ctx.rawBody = await this.bodyData(req);
-    const contentType = Dingus.getRequestContentType(req);
-    if (ctx.rawBody) {
-      this.parseBody(contentType, ctx);
-      delete ctx.rawBody;
-    }
+    return super.ingestBody(req, res, ctx, {
+      parseEmptyBody: false,
+    });
   }
 
 
@@ -297,7 +274,7 @@ class Service extends Dingus {
     const _scope = _fileScope('handlerGetAdminLogin');
     this.logger.debug(_scope, 'called', { req: common.requestLogData(req), ctx });
 
-    Service.setHeadHandler(req, res, ctx);
+    Dingus.setHeadHandler(req, res, ctx);
 
     this.setResponseType(this.responseTypes, req, res, ctx);