Skip to content

Commit 99c7aeb

Browse files
author
Mikko Tiihonen
committed
Use new configurable negotiator api for encoding sorting
1 parent 85ad87c commit 99c7aeb

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ Compression tips:
132132
gzip encoders. Brotli compresses generally 15-20% better than gzip.
133133
* Use zopfli for gzip compression for and extra 5% benefit for all browsers.
134134

135+
##### encodingNegotiatorOptions
136+
137+
Allows configuring the [encoding negotation options](https://github.com/jshttp/negotiator#sort-options).
138+
135139
##### root
136140

137141
Serve files relative to `path`.

index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ function SendStream (req, path, options) {
163163
? opts.precompressionFormats
164164
: this._precompressionFormats
165165

166+
this._encodingNegotiatorOptions = opts.encodingNegotiatorOptions !== undefined
167+
? opts.encodingNegotiatorOptions
168+
: { sortPreference: 'clientThenServer'}
169+
166170
this._index = opts.index !== undefined
167171
? normalizeList(opts.index, 'index option')
168172
: ['index.html']
@@ -345,7 +349,7 @@ SendStream.prototype.isConditionalGET = function isConditionalGET () {
345349

346350
SendStream.prototype.getAcceptEncodingExtensions = function() {
347351
var self = this
348-
var negotiatedEncodings = new Negotiator(this.req).encodings(self._precompressionEncodings)
352+
var negotiatedEncodings = new Negotiator(this.req).encodings(self._precompressionEncodings, this._encodingNegotiatorOptions)
349353
var accepted = []
350354
for (var e = 0; e < negotiatedEncodings.length; e++) {
351355
var encoding = negotiatedEncodings[e]

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"http-errors": "~1.5.0",
2525
"mime": "1.3.4",
2626
"ms": "0.7.1",
27-
"negotiator": "jshttp/negotiator#d9907aec0585476d9a0c4271e464f7c6e4633049",
27+
"negotiator": "jshttp/negotiator#6038bf698c522c1883a1113c834e53256b35584f",
2828
"on-finished": "~2.3.0",
2929
"range-parser": "~1.2.0",
3030
"statuses": "~1.3.0",

0 commit comments

Comments
 (0)