Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/http-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 16 additions & 7 deletions test/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

Expand Down