Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #490 from Olegas/master

Empty response body (3-rd argument) must be passed to callback as an empty string
  • Loading branch information...
commit 9e1a5dc93795ad6a12dbbe7667a22de7b329f04b 2 parents 88d8d5b + d05b6ba
@mikeal mikeal authored
Showing with 23 additions and 0 deletions.
  1. +3 −0  index.js
  2. +20 −0 tests/test-emptyBody.js
View
3  index.js
@@ -853,6 +853,9 @@ Request.prototype.onResponse = function (response) {
} catch (e) {}
}
debug('emitting complete', self.uri.href)
+ if(response.body == undefined && !self._json) {
+ response.body = "";
+ }
self.emit('complete', response, response.body)
})
}
View
20 tests/test-emptyBody.js
@@ -0,0 +1,20 @@
+var request = require('../index')
+ , http = require('http')
+ , assert = require('assert')
+ ;
+
+var s = http.createServer(function (req, resp) {
+ resp.statusCode = 200
+ resp.end('')
+}).listen(8080, function () {
+ var r = request('http://localhost:8080', function (e, resp, body) {
+ assert.equal(resp.statusCode, 200)
+ assert.equal(body, "")
+
+ var r2 = request({ url: 'http://localhost:8080', json: {} }, function (e, resp, body) {
+ assert.equal(resp.statusCode, 200)
+ assert.equal(body, undefined)
+ s.close()
+ });
+ })
+})
Please sign in to comment.
Something went wrong with that request. Please try again.