Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
endWithCompress(request: Request, data: any) {
// if compress is disable
const encoding: string | false = request.acceptsEncodings('gzip', 'deflate', 'identity');
if (!encoding || encoding === 'identity') return this.end(request, data);
if (!compressible(this.getType())) return this.end(request, data);
const threshold = this.app.get('config').get('app.threshold', 1024);
if (threshold > this.getLength()) return this.end(request, data);
this.setHeader('Content-Encoding', encoding);
this.removeHeader('Content-Length');
const stream = encodingMethods[encoding as 'gzip' | 'deflate']({});
if (data instanceof Stream) {
data.pipe(stream);
} else {
stream.end(data);
}
filter: type => !(/event-stream/i.test(type)) && compressible(type),
}));
export const shouldCompress = function({ contentType }) {
return compressible(contentType)
}