From 21793200619ba5dd45f9b05db2bfbed421674246 Mon Sep 17 00:00:00 2001 From: "Stanley (QXU)" Date: Wed, 27 Mar 2024 23:10:45 +0800 Subject: [PATCH] Code simplification --- index.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index 6239135..7343f98 100644 --- a/index.js +++ b/index.js @@ -280,11 +280,10 @@ function buildRouteCompress (fastify, params, routeOptions, decorateOnly) { } setVaryHeader(reply) - params.removeContentLengthHeader - ? reply - .header('Content-Encoding', encoding) - .removeHeader('content-length') - : reply.header('Content-Encoding', encoding) + reply.header('Content-Encoding', encoding) + if (params.removeContentLengthHeader) { + reply.removeHeader('content-length') + } stream = zipStream(params.compressStream, encoding) pump(payload, stream, onEnd.bind(reply)) @@ -405,11 +404,10 @@ function compress (params) { } setVaryHeader(this) - params.removeContentLengthHeader - ? this - .header('Content-Encoding', encoding) - .removeHeader('content-length') - : this.header('Content-Encoding', encoding) + this.header('Content-Encoding', encoding) + if (params.removeContentLengthHeader) { + this.removeHeader('content-length') + } stream = zipStream(params.compressStream, encoding) pump(payload, stream, onEnd.bind(this))