Merge pull request #24287 from rburgt/master

compression - added missing default filter method interface
This commit is contained in:
Arthur Ozga
2018-03-15 12:24:54 -07:00
committed by GitHub
2 changed files with 29 additions and 6 deletions
+12 -1
View File
@@ -1,4 +1,3 @@
import express = require('express');
import compress = require('compression');
@@ -7,3 +6,15 @@ app.use(compress());
app.use(compress({
threshold: 512
}));
app.use(compress({
threshold: 512,
filter: (req, res) => {
if (req.headers['x-no-compression']) {
// don't compress responses with this request header
return false;
}
// fallback to standard filter function
return compress.filter(req, res);
}
}));
+17 -5
View File
@@ -1,13 +1,26 @@
// Type definitions for compression
// Project: https://github.com/expressjs/compression
// Definitions by: Santi Albo <https://github.com/santialbo>
// Rob van der Burgt <https://github.com/rburgt>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
import * as express from 'express';
declare function e(options?: e.CompressionOptions): express.RequestHandler;
declare namespace e {
interface CompressionOptions {
/**
* Default filter, used for extending filter given in CompressionOptions
* See https://github.com/expressjs/compression#filter-1 regarding the usage
*/
export function filter(req: express.Request, res: express.Response): boolean;
interface CompressionFilter {
(req: express.Request, res: express.Response): boolean;
}
interface CompressionOptions {
/**
* See https://github.com/expressjs/compression#chunksize regarding the usage.
*/
@@ -31,7 +44,7 @@ declare namespace e {
/**
* See https://github.com/expressjs/compression#threshold regarding the usage.
*/
threshold?: number|string;
threshold?: number | string;
/**
* See https://github.com/expressjs/compression#windowbits regarding the usage.
@@ -41,8 +54,8 @@ declare namespace e {
/**
* See https://github.com/expressjs/compression#filter regarding the usage.
*/
filter?: Function;
filter?: CompressionFilter;
/**
* See https://nodejs.org/api/zlib.html#zlib_class_options regarding the usage.
*/
@@ -55,5 +68,4 @@ declare namespace e {
}
}
declare function e(options?: e.CompressionOptions): express.RequestHandler;
export = e;