Skip to content

Commit

Permalink
Empty body must be passed as empty string, exclude JSON case
Browse files Browse the repository at this point in the history
  • Loading branch information
Olegas committed Mar 25, 2013
1 parent 88d8d5b commit d05b6ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.js
Expand Up @@ -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)
})
}
Expand Down
20 changes: 20 additions & 0 deletions 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()
});
})
})

0 comments on commit d05b6ba

Please sign in to comment.