Enable compression middleware (#10379)
This commit is contained in:
Родитель
2aa169b54f
Коммит
e00edf9359
|
@ -166,6 +166,7 @@
|
|||
"chokidar": "3.5.1",
|
||||
"classnames": "2.3.1",
|
||||
"common-tags": "1.8.0",
|
||||
"compression": "1.7.4",
|
||||
"config": "3.3.6",
|
||||
"connected-react-router": "5.0.1",
|
||||
"core-js": "3.10.1",
|
||||
|
|
|
@ -4,6 +4,7 @@ import https from 'https';
|
|||
|
||||
import 'amo/polyfill';
|
||||
import { oneLine } from 'common-tags';
|
||||
import compression from 'compression';
|
||||
import defaultConfig from 'config';
|
||||
import Express from 'express';
|
||||
import httpContext from 'express-http-context';
|
||||
|
@ -173,6 +174,9 @@ function baseServer(
|
|||
|
||||
app.use(middleware.responseTime({ _config: config, _HotShots }));
|
||||
|
||||
// Enable gzip compression
|
||||
app.use(compression());
|
||||
|
||||
// Set HTTP Strict Transport Security headers
|
||||
app.use(middleware.hsts());
|
||||
|
||||
|
|
|
@ -155,6 +155,15 @@ describe(__filename, () => {
|
|||
});
|
||||
|
||||
describe('app', () => {
|
||||
it('enables gzip compression if client sends accept-encoding', async () => {
|
||||
const { store, sagaMiddleware } = createStoreAndSagas();
|
||||
|
||||
const response = await testClient({ store, sagaMiddleware })
|
||||
.get('/en-US/firefox/')
|
||||
.set('Accept-Encoding', 'gzip');
|
||||
expect(response.headers['content-encoding']).toEqual('gzip');
|
||||
});
|
||||
|
||||
it('preconnects to addons-server CDN', async () => {
|
||||
const config = getFakeConfig({
|
||||
staticHost: undefined,
|
||||
|
@ -285,10 +294,10 @@ describe(__filename, () => {
|
|||
expect(response.statusCode).toEqual(200);
|
||||
});
|
||||
|
||||
it('varies on DNT', async () => {
|
||||
it('varies on DNT and Accept-Encoding', async () => {
|
||||
const response = await testClient().get('/en-US/firefox/');
|
||||
|
||||
expect(response.headers).toMatchObject({ vary: 'DNT' });
|
||||
expect(response.headers).toMatchObject({ vary: 'DNT, Accept-Encoding' });
|
||||
expect(response.statusCode).toEqual(200);
|
||||
});
|
||||
|
||||
|
|
34
yarn.lock
34
yarn.lock
|
@ -1871,7 +1871,7 @@ abbrev@1:
|
|||
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8"
|
||||
integrity sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==
|
||||
|
||||
accepts@^1.3.4, accepts@~1.3.7:
|
||||
accepts@^1.3.4, accepts@~1.3.5, accepts@~1.3.7:
|
||||
version "1.3.7"
|
||||
resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.7.tgz#531bc726517a3b2b41f850021c6cc15eaab507cd"
|
||||
integrity sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==
|
||||
|
@ -2753,6 +2753,11 @@ bundlesize@^0.18.0:
|
|||
gzip-size "^4.0.0"
|
||||
prettycli "^1.4.3"
|
||||
|
||||
bytes@3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.0.0.tgz#d32815404d689699f85a4ea4fa8755dd13a96048"
|
||||
integrity sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=
|
||||
|
||||
bytes@3.1.0, bytes@^3.1.0:
|
||||
version "3.1.0"
|
||||
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.0.tgz#f6cf7933a360e0588fa9fde85651cdc7f805d1f6"
|
||||
|
@ -3389,6 +3394,26 @@ component-emitter@^1.2.1, component-emitter@^1.3.0:
|
|||
resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.3.0.tgz#16e4070fba8ae29b679f2215853ee181ab2eabc0"
|
||||
integrity sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==
|
||||
|
||||
compressible@~2.0.16:
|
||||
version "2.0.18"
|
||||
resolved "https://registry.yarnpkg.com/compressible/-/compressible-2.0.18.tgz#af53cca6b070d4c3c0750fbd77286a6d7cc46fba"
|
||||
integrity sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==
|
||||
dependencies:
|
||||
mime-db ">= 1.43.0 < 2"
|
||||
|
||||
compression@1.7.4:
|
||||
version "1.7.4"
|
||||
resolved "https://registry.yarnpkg.com/compression/-/compression-1.7.4.tgz#95523eff170ca57c29a0ca41e6fe131f41e5bb8f"
|
||||
integrity sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==
|
||||
dependencies:
|
||||
accepts "~1.3.5"
|
||||
bytes "3.0.0"
|
||||
compressible "~2.0.16"
|
||||
debug "2.6.9"
|
||||
on-headers "~1.0.2"
|
||||
safe-buffer "5.1.2"
|
||||
vary "~1.1.2"
|
||||
|
||||
concat-map@0.0.1:
|
||||
version "0.0.1"
|
||||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
|
||||
|
@ -8140,6 +8165,11 @@ mime-db@1.46.0:
|
|||
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.46.0.tgz#6267748a7f799594de3cbc8cde91def349661cee"
|
||||
integrity sha512-svXaP8UQRZ5K7or+ZmfNhg2xX3yKDMUzqadsSqi4NCH/KomcH75MAMYAGVlvXn4+b/xOPhS3I2uHKRUzvjY7BQ==
|
||||
|
||||
"mime-db@>= 1.43.0 < 2":
|
||||
version "1.47.0"
|
||||
resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.47.0.tgz#8cb313e59965d3c05cfbf898915a267af46a335c"
|
||||
integrity sha512-QBmA/G2y+IfeS4oktet3qRZ+P5kPhCKRXxXnQEudYqUaEioAU1/Lq2us3D/t1Jfo4hE9REQPrbB7K5sOczJVIw==
|
||||
|
||||
mime-types@2.1.24:
|
||||
version "2.1.24"
|
||||
resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.24.tgz#b6f8d0b3e951efb77dedeca194cff6d16f676f81"
|
||||
|
@ -8827,7 +8857,7 @@ on-finished@^2.3.0, on-finished@~2.3.0:
|
|||
dependencies:
|
||||
ee-first "1.1.1"
|
||||
|
||||
on-headers@~1.0.1:
|
||||
on-headers@~1.0.1, on-headers@~1.0.2:
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/on-headers/-/on-headers-1.0.2.tgz#772b0ae6aaa525c399e489adfad90c403eb3c28f"
|
||||
integrity sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==
|
||||
|
|
Загрузка…
Ссылка в новой задаче