Comparing version 3.2.2 to 3.3.0
@@ -0,1 +1,5 @@ | ||
2018/09/01 Version 3.3.0 | ||
- Updated dependencies | ||
- Added support for brotli encoding in addition to existing gzip support | ||
2018/08/28 Version 3.2.2 | ||
@@ -2,0 +6,0 @@ - Patchfix for improved accuracy when checking to see if gzip responses are allowed |
@@ -0,0 +0,0 @@ # Contributing Guidelines |
@@ -0,0 +0,0 @@ General format is: contributor, github handle, email. In some cases, the |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
Hello world! |
hello cruel world! |
@@ -35,3 +35,3 @@ #! /usr/bin/env node | ||
// Check to see if we should try to compress a file with gzip. | ||
function shouldCompress(req) { | ||
function shouldCompressGzip(req) { | ||
const headers = req.headers; | ||
@@ -46,2 +46,12 @@ | ||
function shouldCompressBrotli(req) { | ||
const headers = req.headers; | ||
return headers && headers['accept-encoding'] && | ||
headers['accept-encoding'] | ||
.split(',') | ||
.some(el => ['*', 'br'].indexOf(el.trim()) !== -1) | ||
; | ||
} | ||
function hasGzipId12(gzipped, cb) { | ||
@@ -171,3 +181,4 @@ const stream = fs.createReadStream(gzipped, { start: 0, end: 1 }); | ||
let file = null; | ||
let gzipped = null; | ||
let gzippedFile = null; | ||
let brotliFile = null; | ||
@@ -204,3 +215,5 @@ // Strip any null bytes from the url | ||
); | ||
gzipped = `${file}.gz`; | ||
// determine compressed forms if they were to exist | ||
gzippedFile = `${file}.gz`; | ||
brotliFile = `${file}.br`; | ||
@@ -236,3 +249,3 @@ if (serverHeader !== false) { | ||
// Do a MIME lookup, fall back to octet-stream and handle gzip | ||
// special case. | ||
// and brotli special case. | ||
const defaultType = opts.contentType || 'application/octet-stream'; | ||
@@ -246,3 +259,2 @@ let contentType = mime.lookup(file, defaultType); | ||
let stream = null; | ||
if (contentType) { | ||
@@ -255,7 +267,10 @@ charSet = mime.charsets.lookup(contentType, 'utf-8'); | ||
if (file === gzipped) { // is .gz picked up | ||
if (file === gzippedFile) { // is .gz picked up | ||
res.setHeader('Content-Encoding', 'gzip'); | ||
// strip gz ending and lookup mime type | ||
contentType = mime.lookup(path.basename(file, '.gz'), defaultType); | ||
} else if (file === brotliFile) { // is .br picked up | ||
res.setHeader('Content-Encoding', 'br'); | ||
// strip br ending and lookup mime type | ||
contentType = mime.lookup(path.basename(file, '.br'), defaultType); | ||
} | ||
@@ -411,9 +426,9 @@ | ||
// Look for a gzipped file if this is turned on | ||
if (opts.gzip && shouldCompress(req)) { | ||
fs.stat(gzipped, (err, stat) => { | ||
// serve gzip file if exists and is valid | ||
function tryServeWithGzip() { | ||
fs.stat(gzippedFile, (err, stat) => { | ||
if (!err && stat.isFile()) { | ||
hasGzipId12(gzipped, (gzipErr, isGzip) => { | ||
hasGzipId12(gzippedFile, (gzipErr, isGzip) => { | ||
if (!gzipErr && isGzip) { | ||
file = gzipped; | ||
file = gzippedFile; | ||
serve(stat); | ||
@@ -428,2 +443,25 @@ } else { | ||
}); | ||
} | ||
// serve brotli file if exists, otherwise try gzip | ||
function tryServeWithBrotli(shouldTryGzip) { | ||
fs.stat(brotliFile, (err, stat) => { | ||
if (!err && stat.isFile()) { | ||
file = brotliFile; | ||
serve(stat); | ||
} else if (shouldTryGzip) { | ||
tryServeWithGzip(); | ||
} else { | ||
statFile(); | ||
} | ||
}); | ||
} | ||
const shouldTryBrotli = opts.brotli && shouldCompressBrotli(req); | ||
const shouldTryGzip = opts.gzip && shouldCompressGzip(req); | ||
// always try brotli first, next try gzip, finally serve without compression | ||
if (shouldTryBrotli) { | ||
tryServeWithBrotli(shouldTryGzip); | ||
} else if (shouldTryGzip) { | ||
tryServeWithGzip(); | ||
} else { | ||
@@ -430,0 +468,0 @@ statFile(); |
@@ -0,0 +0,0 @@ { |
@@ -11,2 +11,3 @@ { | ||
"gzip": true, | ||
"brotli": false, | ||
"defaultExt": ".html", | ||
@@ -13,0 +14,0 @@ "handleError": true, |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -17,2 +17,3 @@ 'use strict'; | ||
let gzip = defaults.gzip; | ||
let brotli = defaults.brotli; | ||
let defaultExt = defaults.defaultExt; | ||
@@ -109,2 +110,6 @@ let handleError = defaults.handleError; | ||
if (typeof opts.brotli !== 'undefined' && opts.brotli !== null) { | ||
brotli = opts.brotli; | ||
} | ||
aliases.handleError.some((k) => { | ||
@@ -200,2 +205,3 @@ if (isDeclared(k)) { | ||
gzip, | ||
brotli, | ||
handleError, | ||
@@ -202,0 +208,0 @@ headers, |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ 'use strict'; |
@@ -0,0 +0,0 @@ The MIT License (MIT) |
@@ -5,3 +5,3 @@ { | ||
"description": "A simple static file server middleware", | ||
"version": "3.2.2", | ||
"version": "3.3.0", | ||
"homepage": "https://github.com/jfhbrook/node-ecstatic", | ||
@@ -38,6 +38,6 @@ "repository": { | ||
"eslint-config-airbnb-base": "^11.3.2", | ||
"eslint-plugin-import": "^2.11.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"express": "^4.16.3", | ||
"mkdirp": "^0.5.0", | ||
"request": "^2.85.0", | ||
"request": "^2.88.0", | ||
"tap": "^12.0.1" | ||
@@ -44,0 +44,0 @@ }, |
@@ -100,2 +100,3 @@ # Ecstatic [![build status](https://secure.travis-ci.org/jfhbrook/node-ecstatic.png)](http://travis-ci.org/jfhbrook/node-ecstatic) [![codecov.io](https://codecov.io/github/jfhbrook/node-ecstatic/coverage.svg?branch=master)](https://codecov.io/github/jfhbrook/node-ecstatic?branch=master) | ||
gzip: true, | ||
brotli: false, | ||
defaultExt: 'html', | ||
@@ -213,2 +214,12 @@ handleError: true, | ||
### `opts.brotli` | ||
### `--brotli` | ||
Serve `./public/some-file.js.br` in place of `./public/some-file.js` when the | ||
[brotli encoded](https://github.com/google/brotli) version exists and ecstatic | ||
determines that the behavior is appropriate. If the request does not contain | ||
`br` in the HTTP `accept-encoding` header, ecstatic will instead attempt to | ||
serve a gzipped version (if `opts.gzip` is `true`), or fall back to | ||
`./public.some-file.js`. Defaults to **false**. | ||
### `opts.serverHeader` | ||
@@ -215,0 +226,0 @@ ### `--no-server-header` |
@@ -0,0 +0,0 @@ var fs = require('fs'), |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
315111
1301
300