You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am having problems serving precompressed files with the directory handler.
While the file handler serves the precompressed files, the directory handler seems to skip them and compress the original ones.
You can find a failing test below.
For test purposes, the precompressed file is set larger than the original file, so it is easier to distinguish it in case the server is compressing the orginal file.
// Load modules
var Fs = require('fs');
var Lab = require('lab');
var Hapi = require('hapi');
var Zlib = require('zlib');
// Test shortcuts
var expect = Lab.expect;
var before = Lab.before;
var describe = Lab.experiment;
var it = Lab.test;
describe('Response', function () {
describe('Gzip', function () {
before(function (done) {
var uncompressedContent = '//This is the uncompressed test file';
var precompressedContent = '//This is the pre-compressed test file. It should be longer than the uncompressed one';
Fs.writeFileSync('./testFile.js', uncompressedContent);
Zlib.gzip(precompressedContent, function(err, result){
Fs.writeFileSync('./testFile.js.gz', result);
done();
})
});
it('File handler: returns a gzipped file using precompressed file', function (done) {
var content = Fs.readFileSync('./testFile.js.gz');
var server = new Hapi.Server();
server.route({ method: 'GET', path: '/file', handler: { file: { path: './testFile.js', lookupCompressed: true } } });
server.inject({ url: '/file', headers: { 'accept-encoding': 'gzip' } }, function (res) {
expect(res.headers['content-encoding']).to.equal('gzip');
expect(res.headers['content-length']).to.not.exist;
expect(res.payload.length).to.equal(content.length);
done();
});
});
it('Directory handler: returns a gzipped file using precompressed file', function (done) {
var content = Fs.readFileSync('./testFile.js.gz');
var server = new Hapi.Server();
server.route({ method: 'GET', path: '/{p*}', handler: { directory: { path: './', lookupCompressed: true } } });
server.inject({ url: '/testFile.js', headers: { 'accept-encoding': 'gzip' } }, function (res) {
expect(res.headers['content-encoding']).to.equal('gzip');
expect(res.headers['content-length']).to.not.exist;
// The following fails
expect(res.payload.length).to.equal(content.length);
done();
});
});
});
});
The text was updated successfully, but these errors were encountered:
Hi, I am having problems serving precompressed files with the directory handler.
While the file handler serves the precompressed files, the directory handler seems to skip them and compress the original ones.
You can find a failing test below.
For test purposes, the precompressed file is set larger than the original file, so it is easier to distinguish it in case the server is compressing the orginal file.
The text was updated successfully, but these errors were encountered: