Skip to content

Commit 86d65a9

Browse files
committed
Merge branch 'master' of github.com:expressjs/compression into add-default-encoding
2 parents 24609a6 + 0cd9d86 commit 86d65a9

File tree

5 files changed

+46
-42
lines changed

5 files changed

+46
-42
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
- Node.js 20.x
3636
- Node.js 21.x
3737
- Node.js 22.x
38+
- Node.js 23.x
3839

3940
include:
4041
- name: Node.js 0.8
@@ -63,69 +64,72 @@ jobs:
6364
npm-i: mocha@3.5.3 nyc@10.3.2 supertest@2.0.0
6465

6566
- name: Node.js 4.x
66-
node-version: "4.9"
67+
node-version: "4"
6768
npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2
6869

6970
- name: Node.js 5.x
70-
node-version: "5.12"
71+
node-version: "5"
7172
npm-i: mocha@5.2.0 nyc@11.9.0 supertest@3.4.2
7273

7374
- name: Node.js 6.x
74-
node-version: "6.17"
75+
node-version: "6"
7576
npm-i: mocha@6.2.3 nyc@14.1.1 supertest@6.1.6
7677

7778
- name: Node.js 7.x
78-
node-version: "7.10"
79+
node-version: "7"
7980
npm-i: mocha@6.2.3 nyc@14.1.1 supertest@6.1.6
8081

8182
- name: Node.js 8.x
82-
node-version: "8.16"
83+
node-version: "8"
8384
npm-i: mocha@7.2.0 nyc@14.1.1
8485

8586
- name: Node.js 9.x
86-
node-version: "9.11"
87+
node-version: "9"
8788
npm-i: mocha@7.2.0 nyc@14.1.1
8889

8990
- name: Node.js 10.x
90-
node-version: "10.16"
91+
node-version: "10"
9192
npm-i: mocha@8.4.0
9293

9394
- name: Node.js 11.x
94-
node-version: "11.15"
95+
node-version: "11"
9596
npm-i: mocha@8.4.0
9697

9798
- name: Node.js 12.x
98-
node-version: "12.22"
99+
node-version: "12"
99100

100101
- name: Node.js 13.x
101-
node-version: "13.14"
102+
node-version: "13"
102103

103104
- name: Node.js 14.x
104-
node-version: "14.19"
105+
node-version: "14"
105106

106107
- name: Node.js 15.x
107-
node-version: "15.14"
108+
node-version: "15"
108109

109110
- name: Node.js 16.x
110-
node-version: "16.15"
111+
node-version: "16"
111112

112113
- name: Node.js 17.x
113-
node-version: "17.9"
114+
node-version: "17"
114115

115116
- name: Node.js 18.x
116-
node-version: "18.14"
117+
node-version: "18"
117118

118119
- name: Node.js 19.x
119-
node-version: "19.6"
120+
node-version: "19"
120121

121122
- name: Node.js 20.x
122-
node-version: "20.12"
123+
node-version: "20"
123124

124125
- name: Node.js 21.x
125-
node-version: "21.7"
126+
node-version: "21"
126127

127128
- name: Node.js 22.x
128-
node-version: "22.0"
129+
node-version: "22"
130+
131+
- name: Node.js 23.x
132+
node-version: "23"
129133

130134
steps:
131135
- uses: actions/checkout@v4

HISTORY.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
unreleased
22
==========
33
* Add the defaultEncoding option for requests without `Accept-Encoding` header
4-
* deps: accepts@~1.3.8
5-
- Fix sorting encoding with extra parameters
6-
- deps: mime-types@~2.1.34
7-
- deps: negotiator@0.6.3
4+
5+
1.7.5 / 2024-10-31
6+
==========
7+
* deps: Replace accepts with negotiator@~0.6.4
8+
- Add preference option
9+
* deps: bytes@3.1.2
10+
- Add petabyte (`pb`) support
11+
- Fix "thousandsSeparator" incorrecting formatting fractional part
12+
- Fix return value for un-parsable strings
813
* deps: compressible@~2.0.18
914
- Mark `font/ttf` as compressible
1015
- Remove compressible from `multipart/mixed`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var compression = require('compression')
3131
### compression([options])
3232

3333
Returns the compression middleware using the given `options`. The middleware
34-
will attempt to compress response bodies for all request that traverse through
34+
will attempt to compress response bodies for all requests that traverse through
3535
the middleware, based on the given `options`.
3636

3737
This middleware will never compress responses that include a `Cache-Control`

index.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @private
1515
*/
1616

17-
var accepts = require('accepts')
17+
var Negotiator = require('negotiator')
1818
var Buffer = require('safe-buffer').Buffer
1919
var bytes = require('bytes')
2020
var compressible = require('compressible')
@@ -177,13 +177,8 @@ function compression (options) {
177177
}
178178

179179
// compression method
180-
var accept = accepts(req)
181-
var method = accept.encoding(['gzip', 'deflate', 'identity'])
182-
183-
// we really don't prefer deflate
184-
if (method === 'deflate' && accept.encoding(['gzip'])) {
185-
method = accept.encoding(['gzip', 'identity'])
186-
}
180+
var negotiator = new Negotiator(req)
181+
var method = negotiator.encoding(['gzip', 'deflate', 'identity'], ['gzip'])
187182

188183
// if no method is found, use the default encoding
189184
if (encodingSupported.indexOf(defaultEncoding) !== -1 && !req.headers['accept-encoding']) {
@@ -253,9 +248,9 @@ function chunkLength (chunk, encoding) {
253248
return 0
254249
}
255250

256-
return !Buffer.isBuffer(chunk)
257-
? Buffer.byteLength(chunk, encoding)
258-
: chunk.length
251+
return Buffer.isBuffer(chunk)
252+
? chunk.length
253+
: Buffer.byteLength(chunk, encoding)
259254
}
260255

261256
/**
@@ -294,7 +289,7 @@ function shouldTransform (req, res) {
294289
*/
295290

296291
function toBuffer (chunk, encoding) {
297-
return !Buffer.isBuffer(chunk)
298-
? Buffer.from(chunk, encoding)
299-
: chunk
292+
return Buffer.isBuffer(chunk)
293+
? chunk
294+
: Buffer.from(chunk, encoding)
300295
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"name": "compression",
33
"description": "Node.js compression middleware",
4-
"version": "1.7.4",
4+
"version": "1.7.5",
55
"contributors": [
66
"Douglas Christopher Wilson <doug@somethingdoug.com>",
77
"Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)"
88
],
99
"license": "MIT",
1010
"repository": "expressjs/compression",
1111
"dependencies": {
12-
"accepts": "~1.3.8",
13-
"bytes": "3.0.0",
12+
"bytes": "3.1.2",
1413
"compressible": "~2.0.18",
1514
"debug": "2.6.9",
15+
"negotiator": "~0.6.4",
1616
"on-headers": "~1.0.2",
1717
"safe-buffer": "5.2.1",
1818
"vary": "~1.1.2"
@@ -40,7 +40,7 @@
4040
},
4141
"scripts": {
4242
"lint": "eslint .",
43-
"test": "mocha --check-leaks --reporter spec --bail",
43+
"test": "mocha --check-leaks --reporter spec",
4444
"test-ci": "nyc --reporter=lcovonly --reporter=text npm test",
4545
"test-cov": "nyc --reporter=html --reporter=text npm test"
4646
}

0 commit comments

Comments
 (0)