Skip to content

Commit

Permalink
Merge pull request #1330 from seanstrom/feature/empty-buffer-null-res…
Browse files Browse the repository at this point in the history
…ponse

Return empty buffer upon empty response body and encoding is set to null
  • Loading branch information
nylen committed Dec 31, 2014
2 parents 4455e53 + f92ed13 commit bd0aa25
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion request.js
Expand Up @@ -1321,7 +1321,7 @@ Request.prototype.onRequestResponse = function (response) {
}
debug('emitting complete', self.uri.href)
if(typeof response.body === 'undefined' && !self._json) {
response.body = ''
response.body = self.encoding === null ? new Buffer(0) : ''
}
self.emit('complete', response, response.body)
})
Expand Down
14 changes: 13 additions & 1 deletion tests/test-emptyBody.js
Expand Up @@ -15,7 +15,7 @@ tape('setup', function(t) {
})
})

tape('empty body', function(t) {
tape('empty body with encoding', function(t) {
request('http://localhost:6767', function(err, res, body) {
t.equal(err, null)
t.equal(res.statusCode, 200)
Expand All @@ -24,6 +24,18 @@ tape('empty body', function(t) {
})
})

tape('empty body without encoding', function(t) {
request({
url: 'http://localhost:6767',
encoding: null
}, function(err, res, body) {
t.equal(err, null)
t.equal(res.statusCode, 200)
t.same(body, new Buffer(0))
t.end()
})
})

tape('empty JSON body', function(t) {
request({
url: 'http://localhost:6767',
Expand Down

0 comments on commit bd0aa25

Please sign in to comment.