Skip to content

Commit

Permalink
Test octet-stream
Browse files Browse the repository at this point in the history
  • Loading branch information
kornelski committed Jan 25, 2017
1 parent 5615a81 commit 2452309
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
15 changes: 15 additions & 0 deletions test/node/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ describe('res.body', function(){
request
.get(base + '/image')
.end(function(err, res){
res.type.should.equal('image/png');
Buffer.isBuffer(res.body).should.be.true();
(res.body.length - img.length).should.equal(0);
done();
});
});
});
describe('application/octet-stream', function(){
it('should parse the body', function(done){
request
.get(base + '/image-as-octets')
.buffer(true) // that's tech debt :(
.end(function(err, res){
res.type.should.equal('application/octet-stream');
Buffer.isBuffer(res.body).should.be.true();
(res.body.length - img.length).should.equal(0);
done();
});
Expand Down
10 changes: 8 additions & 2 deletions test/support/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,16 @@ app.get('/manny', function(req, res){
res.status(200).json({name:"manny"});
});

app.get('/image', function(req, res){
function serveImageWithType(res, type) {
var img = fs.readFileSync(__dirname + '/../node/fixtures/test.png');
res.writeHead(200, {'Content-Type': 'image/png' });
res.writeHead(200, {'Content-Type': type });
res.end(img, 'binary');
}
app.get('/image', function(req, res){
serveImageWithType(res, 'image/png');
});
app.get('/image-as-octets', function(req, res){
serveImageWithType(res, 'application/octet-stream');
});

app.get('/chunked-json', function(req, res){
Expand Down

0 comments on commit 2452309

Please sign in to comment.