diff --git a/lib/http-context.js b/lib/http-context.js index 21455447..36e5d29e 100644 --- a/lib/http-context.js +++ b/lib/http-context.js @@ -475,7 +475,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 e029b39c..2887e8ef 100644 --- a/test/streams.js +++ b/test/streams.js @@ -30,7 +30,7 @@ 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 = [ @@ -40,15 +40,24 @@ describe('strong-remoting', function() { fs.createReadStream.returns = { arg: 'res', type: 'stream' }; fs.createReadStream.http = { verb: 'get', - // path: '/fs/createReadStream', pipe: { 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); }); + + it('should stream the file output with no compression', function(done) { + createSteam(); + request(app)['get']('/fs/createReadStream') + .expect('Content-Encoding', 'x-no-compression'); + done(); + }); }); describe('a function returning a ReadableStream', function() {