|
| 1 | +var bytes = require('bytes'); |
1 | 2 | var crypto = require('crypto'); |
2 | 3 | var http = require('http'); |
3 | 4 | var request = require('supertest'); |
@@ -275,6 +276,52 @@ describe('compress()', function(){ |
275 | 276 | .end() |
276 | 277 | }) |
277 | 278 |
|
| 279 | + it('should transfer large bodies', function (done) { |
| 280 | + var len = bytes('1mb') |
| 281 | + var buf = new Buffer(len) |
| 282 | + var server = createServer({ threshold: 0 }, function (req, res) { |
| 283 | + res.setHeader('Content-Type', 'text/plain') |
| 284 | + res.end(buf) |
| 285 | + }) |
| 286 | + |
| 287 | + buf.fill('.') |
| 288 | + |
| 289 | + request(server) |
| 290 | + .get('/') |
| 291 | + .set('Accept-Encoding', 'gzip') |
| 292 | + .expect('Transfer-Encoding', 'chunked') |
| 293 | + .expect('Content-Encoding', 'gzip', function (err, res) { |
| 294 | + if (err) return done(err) |
| 295 | + should(res.text).equal(buf.toString()) |
| 296 | + res.text.length.should.equal(len) |
| 297 | + done() |
| 298 | + }) |
| 299 | + }) |
| 300 | + |
| 301 | + it('should transfer large bodies with multiple writes', function (done) { |
| 302 | + var len = bytes('40kb') |
| 303 | + var buf = new Buffer(len) |
| 304 | + var server = createServer({ threshold: 0 }, function (req, res) { |
| 305 | + res.setHeader('Content-Type', 'text/plain') |
| 306 | + res.write(buf) |
| 307 | + res.write(buf) |
| 308 | + res.write(buf) |
| 309 | + res.end(buf) |
| 310 | + }) |
| 311 | + |
| 312 | + buf.fill('.') |
| 313 | + |
| 314 | + request(server) |
| 315 | + .get('/') |
| 316 | + .set('Accept-Encoding', 'gzip') |
| 317 | + .expect('Transfer-Encoding', 'chunked') |
| 318 | + .expect('Content-Encoding', 'gzip', function (err, res) { |
| 319 | + if (err) return done(err) |
| 320 | + res.text.length.should.equal(len * 4) |
| 321 | + done() |
| 322 | + }) |
| 323 | + }) |
| 324 | + |
278 | 325 | describe('threshold', function(){ |
279 | 326 | it('should not compress responses below the threshold size', function(done){ |
280 | 327 | var server = createServer({ threshold: '1kb' }, function (req, res) { |
|
0 commit comments