-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Serve pre-gzipped files instead of gzipping them on the fly
- Loading branch information
Showing
6 changed files
with
54 additions
and
4 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
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,48 @@ | ||
'use strict'; | ||
var HttpMaster = require('../src/HttpMaster'); | ||
var expect = require('chai').expect; | ||
require('should'); | ||
|
||
var testUtils = require('../src/testUtils'); | ||
var rp = require('request-promise'); | ||
|
||
describe('static middleware', function() { | ||
|
||
var master; | ||
before(function(done) { | ||
master = new HttpMaster(); | ||
master.on('error', done); | ||
master.init({ | ||
workerCount: 0, | ||
ports: { | ||
23441: 'static -> ./tests/static_data' | ||
} | ||
}, function(err) { | ||
done(err); | ||
}); | ||
}); | ||
|
||
it('should serve uncompressed test.txt', function(cb) { | ||
rp('http://localhost:23441/test.txt').then(function(data) { | ||
expect(data).to.equal('foo bar'); | ||
}).nodeify(cb); | ||
}); | ||
|
||
it('should work with gzip capable client even if no .gz variant of a file exists', function(cb) { | ||
rp('http://localhost:23441/test.txt', {gzip: true}).then(function(data) { | ||
expect(data).to.equal('foo bar'); | ||
}).nodeify(cb); | ||
}); | ||
|
||
it('should serve pre-compressed test2.txt to gzip capable client', function(cb) { | ||
rp('http://localhost:23441/test2.txt', {gzip: true}).then(function(data) { | ||
expect(data).to.equal('foo bar'); | ||
}).nodeify(cb); | ||
}); | ||
|
||
it('should 404 while sending file that is only gzipped and if client is not gzip capable', function(cb) { | ||
rp('http://localhost:23441/test2.txt').then(function(data) { | ||
expect(data).to.equal('not found'); | ||
}).nodeify(cb); | ||
}); | ||
}); |
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 @@ | ||
not found |
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 @@ | ||
foo bar |
Binary file not shown.