From 295fa1dd6390c1b9e0049f187804d248f3b6f48c Mon Sep 17 00:00:00 2001 From: Candy Date: Mon, 30 May 2016 16:53:17 -0400 Subject: [PATCH] Set to no compression when using change stream --- lib/http-context.js | 6 +++++- test/streams.js | 23 ++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/http-context.js b/lib/http-context.js index 774e4fc6..9fb80577 100644 --- a/lib/http-context.js +++ b/lib/http-context.js @@ -482,7 +482,11 @@ HttpContext.prototype.shouldReturnEventStream = function() { var format = query._format; var acceptable = req.accepts('text/event-stream'); - return (format === 'event-stream') || acceptable; + var returnEventStream = (format === 'event-stream') || acceptable; + if (returnEventStream) { + this.res.setHeader('Content-Encoding', 'x-no-compression'); + } + return returnEventStream; }; HttpContext.prototype.respondWithEventStream = function(stream) { diff --git a/test/streams.js b/test/streams.js index b0cf5f22..e2f7e534 100644 --- a/test/streams.js +++ b/test/streams.js @@ -37,24 +37,33 @@ describe('strong-remoting', function() { .expect('Content-Type', /json/); } - it('should stream the file output', function(done) { + function createSteam() { remotes.fs = fs; fs.createReadStream.shared = true; fs.createReadStream.accepts = [ { arg: 'path', type: 'string' }, - { arg: 'encoding', type: 'string' } + { arg: 'encoding', type: 'string' }, ]; - fs.createReadStream.returns = {arg: 'res', type: 'stream'}; + fs.createReadStream.returns = { arg: 'res', type: 'stream' }; fs.createReadStream.http = { verb: 'get', - // path: '/fs/createReadStream', pipe: { - dest: 'res' - } + dest: 'res', + }, }; + } + it('should stream the file output', function(done) { + createSteam(); json('get', '/fs/createReadStream?path=' + __dirname + '/data/foo.json&encoding=utf8') - .expect({bar: 'baz'}, done); + .expect({ bar: 'baz' }, done); + }); + + it('should stream the file output with no compression', function(done) { + createSteam(); + request(app).get('/fs/createReadStream') + .expect('Content-Encoding', 'x-no-compression'); + done(); }); });