-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from jfhbrook/revert-230-revert-228-brotli-en…
…coding Fix and pull in brotli encoding (aka `Revert "Revert "Add support for brotli encoding""`)
- Loading branch information
Showing
14 changed files
with
264 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ coverage | |
*.dat | ||
*.out | ||
*.pid | ||
*.gz | ||
|
||
pids | ||
logs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
'use strict'; | ||
|
||
const test = require('tap').test; | ||
const ecstatic = require('../lib/ecstatic'); | ||
const http = require('http'); | ||
const request = require('request'); | ||
|
||
const root = `${__dirname}/public`; | ||
|
||
test('serves brotli-encoded file when available', (t) => { | ||
t.plan(3); | ||
|
||
const server = http.createServer(ecstatic({ | ||
root, | ||
brotli: true, | ||
autoIndex: true | ||
})); | ||
|
||
server.listen(() => { | ||
const port = server.address().port; | ||
const options = { | ||
uri: `http://localhost:${port}/brotli`, | ||
headers: { | ||
'accept-encoding': 'gzip, deflate, br' | ||
} | ||
}; | ||
|
||
request.get(options, (err, res) => { | ||
t.ifError(err); | ||
t.equal(res.statusCode, 200); | ||
t.equal(res.headers['content-encoding'], 'br'); | ||
}); | ||
}); | ||
t.once('end', () => { | ||
server.close(); | ||
}); | ||
}); | ||
|
||
test('serves gzip-encoded file when brotli not available', (t) => { | ||
t.plan(3); | ||
|
||
const server = http.createServer(ecstatic({ | ||
root, | ||
brotli: true, | ||
gzip: true, | ||
autoIndex: true | ||
})); | ||
|
||
server.listen(() => { | ||
const port = server.address().port; | ||
const options = { | ||
uri: `http://localhost:${port}/gzip`, | ||
headers: { | ||
'accept-encoding': 'gzip, deflate, br' | ||
} | ||
}; | ||
|
||
request.get(options, (err, res) => { | ||
t.ifError(err); | ||
t.equal(res.statusCode, 200); | ||
t.equal(res.headers['content-encoding'], 'gzip'); | ||
}); | ||
}); | ||
t.once('end', () => { | ||
server.close(); | ||
}); | ||
}); | ||
|
||
test('serves gzip-encoded file when brotli not accepted', (t) => { | ||
t.plan(3); | ||
|
||
const server = http.createServer(ecstatic({ | ||
root, | ||
brotli: true, | ||
gzip: true, | ||
autoIndex: true | ||
})); | ||
|
||
server.listen(() => { | ||
const port = server.address().port; | ||
const options = { | ||
uri: `http://localhost:${port}/brotli`, | ||
headers: { | ||
'accept-encoding': 'gzip, deflate' | ||
} | ||
}; | ||
|
||
request.get(options, (err, res) => { | ||
t.ifError(err); | ||
t.equal(res.statusCode, 200); | ||
t.equal(res.headers['content-encoding'], 'gzip'); | ||
}); | ||
}); | ||
t.once('end', () => { | ||
server.close(); | ||
}); | ||
}); | ||
|
||
test('serves gzip-encoded file when brotli not enabled', (t) => { | ||
t.plan(3); | ||
|
||
const server = http.createServer(ecstatic({ | ||
root, | ||
brotli: false, | ||
gzip: true, | ||
autoIndex: true | ||
})); | ||
|
||
server.listen(() => { | ||
const port = server.address().port; | ||
const options = { | ||
uri: `http://localhost:${port}/brotli`, | ||
headers: { | ||
'accept-encoding': 'gzip, deflate, br' | ||
} | ||
}; | ||
|
||
request.get(options, (err, res) => { | ||
t.ifError(err); | ||
t.equal(res.statusCode, 200); | ||
t.equal(res.headers['content-encoding'], 'gzip'); | ||
}); | ||
}); | ||
t.once('end', () => { | ||
server.close(); | ||
}); | ||
}); | ||
|
||
test('serves unencoded file when compression not accepted', (t) => { | ||
t.plan(3); | ||
|
||
const server = http.createServer(ecstatic({ | ||
root, | ||
brotli: true, | ||
gzip: true, | ||
autoIndex: true | ||
})); | ||
|
||
server.listen(() => { | ||
const port = server.address().port; | ||
const options = { | ||
uri: `http://localhost:${port}/brotli`, | ||
headers: { | ||
'accept-encoding': '' | ||
} | ||
}; | ||
|
||
request.get(options, (err, res) => { | ||
t.ifError(err); | ||
t.equal(res.statusCode, 200); | ||
t.equal(res.headers['content-encoding'], undefined); | ||
}); | ||
}); | ||
t.once('end', () => { | ||
server.close(); | ||
}); | ||
}); | ||
|
||
test('serves unencoded file when compression not enabled', (t) => { | ||
t.plan(3); | ||
|
||
const server = http.createServer(ecstatic({ | ||
root, | ||
brotli: false, | ||
gzip: false, | ||
autoIndex: true | ||
})); | ||
|
||
server.listen(() => { | ||
const port = server.address().port; | ||
const options = { | ||
uri: `http://localhost:${port}/brotli`, | ||
headers: { | ||
'accept-encoding': 'gzip, deflate, br' | ||
} | ||
}; | ||
|
||
request.get(options, (err, res) => { | ||
t.ifError(err); | ||
t.equal(res.statusCode, 200); | ||
t.equal(res.headers['content-encoding'], undefined); | ||
}); | ||
}); | ||
t.once('end', () => { | ||
server.close(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ecstatic |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
brotli, but I'm not compressed!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
�brotli, compressed!! | ||
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
You've been duped! This is not compressed! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ecstatic |
Oops, something went wrong.