Skip to content

Commit

Permalink
Read responseType property from the correct object
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Dupouy committed Mar 17, 2017
1 parent a1a43aa commit 626c2d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ Request.prototype._end = function() {
var multipart = 'multipart' == type;
var redirect = isRedirect(res.statusCode);
var parser = self._parser;
var responseType = self._responseType;

self.res = res;

Expand All @@ -828,7 +829,7 @@ Request.prototype._end = function() {
}

if (!parser) {
if (this._responseType) {
if (responseType) {
parser = exports.parse.image; // It's actually a generic Buffer
buffer = true;
} else if (multipart) {
Expand Down
13 changes: 13 additions & 0 deletions test/node/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,17 @@ describe('res.body', function(){
});
});
});
describe('application/octet-stream', function(){
it('should parse the body (using responseType)', function(done){
request
.get(base + '/image-as-octets')
.responseType('blob')
.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();
});
});
});
});

0 comments on commit 626c2d4

Please sign in to comment.