Christian Fraß
[add] server:lib:node_modules
Christian Fraß commited 6e9c872 at 2021-03-08 23:52:07
compression_spec.js
var should = require('should'),
needle = require('./../'),
http = require('http'),
zlib = require('zlib'),
stream = require('stream'),
port = 11123,
server;
describe('compression', function(){
require.bind(null, 'zlib').should.not.throw()
var jsonData = '{"foo":"bar"}';
describe('when server supports compression', function(){
before(function(){
server = http.createServer(function(req, res) {
var raw = new stream.PassThrough();
var acceptEncoding = req.headers['accept-encoding'];
if (!acceptEncoding) {
acceptEncoding = '';
}
if (acceptEncoding.match(/\bdeflate\b/)) {
res.setHeader('Content-Encoding', 'deflate');
raw.pipe(zlib.createDeflate()).pipe(res);
} else if (acceptEncoding.match(/\bgzip\b/)) {
res.setHeader('Content-Encoding', 'gzip');
raw.pipe(zlib.createGzip()).pipe(res);
} else if (acceptEncoding.match(/\bbr\b/)) {
res.setHeader('Content-Encoding', 'br');
raw.pipe(zlib.createBrotliCompress()).pipe(res);
} else {
raw.pipe(res);
}
res.setHeader('Content-Type', 'application/json')
if (req.headers['with-bad']) {
res.end('foo'); // end, no deflate data
} else {
raw.end(jsonData)
}
})
server.listen(port);
});
after(function(done){
 
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX