Skip to content

Commit

Permalink
Use new configurable negotiator api for encoding sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikko Tiihonen committed Sep 16, 2016
1 parent 85ad87c commit 99c7aeb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ Compression tips:
gzip encoders. Brotli compresses generally 15-20% better than gzip.
* Use zopfli for gzip compression for and extra 5% benefit for all browsers.

##### encodingNegotiatorOptions

Allows configuring the [encoding negotation options](https://github.com/jshttp/negotiator#sort-options).

##### root

Serve files relative to `path`.
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ function SendStream (req, path, options) {
? opts.precompressionFormats
: this._precompressionFormats

this._encodingNegotiatorOptions = opts.encodingNegotiatorOptions !== undefined
? opts.encodingNegotiatorOptions
: { sortPreference: 'clientThenServer'}

this._index = opts.index !== undefined
? normalizeList(opts.index, 'index option')
: ['index.html']
Expand Down Expand Up @@ -345,7 +349,7 @@ SendStream.prototype.isConditionalGET = function isConditionalGET () {

SendStream.prototype.getAcceptEncodingExtensions = function() {
var self = this
var negotiatedEncodings = new Negotiator(this.req).encodings(self._precompressionEncodings)
var negotiatedEncodings = new Negotiator(this.req).encodings(self._precompressionEncodings, this._encodingNegotiatorOptions)
var accepted = []
for (var e = 0; e < negotiatedEncodings.length; e++) {
var encoding = negotiatedEncodings[e]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"http-errors": "~1.5.0",
"mime": "1.3.4",
"ms": "0.7.1",
"negotiator": "jshttp/negotiator#d9907aec0585476d9a0c4271e464f7c6e4633049",
"negotiator": "jshttp/negotiator#6038bf698c522c1883a1113c834e53256b35584f",
"on-finished": "~2.3.0",
"range-parser": "~1.2.0",
"statuses": "~1.3.0",
Expand Down

0 comments on commit 99c7aeb

Please sign in to comment.