Skip to content

Commit 42bb9cb

Browse files
Add switch for GZIP Content-Encoding
1 parent b9b32ea commit 42bb9cb

File tree

6 files changed

+92
-4
lines changed

6 files changed

+92
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ Options:
266266
--static, -s Set static files directory
267267
--read-only, --ro Allow only GET requests [boolean]
268268
--no-cors, --nc Disable Cross-Origin Resource Sharing [boolean]
269+
--no-gzip, --ng Disable GZIP Content-Encoding [boolean]
269270
--snapshots, -S Set snapshots directory [default: "."]
270271
--delay, -d Add delay to responses (ms)
271272
--id, -i Set database id property (e.g. _id) [default: "id"]

src/cli/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ module.exports = function () {
4141
alias: 'nc',
4242
description: 'Disable Cross-Origin Resource Sharing'
4343
},
44+
'no-gzip': {
45+
alias: 'ng',
46+
description: 'Disable GZIP Content-Encoding'
47+
},
4448
snapshots: {
4549
alias: 'S',
4650
description: 'Set snapshots directory',
@@ -69,6 +73,7 @@ module.exports = function () {
6973
.boolean('read-only')
7074
.boolean('quiet')
7175
.boolean('no-cors')
76+
.boolean('no-gzip')
7277
.help('help').alias('help', 'h')
7378
.version(pkg.version).alias('version', 'v')
7479
.example('$0 db.json', '')

src/cli/run.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ function createApp (source, object, routes, argv) {
4545
var defaultsOpts = {
4646
logger: !argv.quiet,
4747
readOnly: argv.readOnly,
48-
noCors: argv.noCors
48+
noCors: argv.noCors,
49+
noGzip: argv.noGzip
4950
}
5051

5152
if (argv.static) {

src/server/defaults.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ module.exports = function (opts) {
1919
var arr = []
2020

2121
// Compress all requests
22-
arr.push(compression())
22+
if (!opts.noGzip) {
23+
arr.push(compression())
24+
}
2325

2426
// Logger
2527
if (opts.logger) {

test/cli/fixtures/seed.js

Lines changed: 27 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/cli/index.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,60 @@ describe('cli', function () {
176176

177177
})
178178

179+
describe('db.json --no-gzip=true', function () {
180+
181+
beforeEach(function (done) {
182+
child = cli(['fixtures/seed.js', '--no-gzip=true'])
183+
serverReady(PORT, done)
184+
})
185+
186+
it('should not set Content-Encoding to gzip', function (done) {
187+
var origin = 'http://example.com'
188+
189+
request.get('/posts')
190+
.set('Origin', origin)
191+
.expect(200)
192+
.end(function (err, res) {
193+
if (err) {
194+
done(err)
195+
return
196+
} else if ('content-encoding' in res.headers) {
197+
done(new Error('Content-Encoding is set to gzip'))
198+
} else {
199+
done()
200+
}
201+
})
202+
})
203+
204+
})
205+
206+
describe('db.json --no-gzip=false', function () {
207+
208+
beforeEach(function (done) {
209+
child = cli(['fixtures/seed.js', '--no-gzip=false'])
210+
serverReady(PORT, done)
211+
})
212+
213+
it('should set Content-Encoding to gzip', function (done) {
214+
var origin = 'http://example.com'
215+
216+
request.get('/posts')
217+
.set('Origin', origin)
218+
.expect(200)
219+
.end(function (err, res) {
220+
if (err) {
221+
done(err)
222+
return
223+
} else if ('content-encoding' in res.headers) {
224+
done()
225+
} else {
226+
done(new Error('Content-Encoding is not set to gzip'))
227+
}
228+
})
229+
})
230+
231+
})
232+
179233
// FIXME test fails on OS X and maybe on Windows
180234
// But manually updating db.json works...
181235
if (os.platform() === 'linux') {

0 commit comments

Comments
 (0)