const zlib = require("zlib");

/**
 * Enable GZip compression for an HTTP exchange
 *
 * @param {Request} request
 * @param {Response} response
 * @param {Buffer} data
 */
function gzip(request, response) {
  if (!request.headers["accept-encoding"].includes("gzip")) return;

  const { writeHead, write, end } = response;
  let myStatusCode, myHeaders;

  response.writeHead = (statusCode, headers) => {
    myStatusCode = statusCode;
    myHeaders = headers;
  };
  response.write = (buffer, dataType) => {
    const compressedBuffer = zlib.gzipSync(buffer);
    writeHead.call(response, myStatusCode, {
      ...myHeaders,
      "Content-Encoding": "gzip",
      "Content-Length": compressedBuffer.length
    });
    write.call(response, compressedBuffer, dataType);
    end.call(response);
  };
}

module.exports = gzip;

@@ -207,16 +207,17 @@
 %0A  if (!
+(
 request.
@@ -242,16 +242,23 @@
 coding%22%5D
+ %7C%7C %22%22)
 .include

fix server accept-encoding handling