Skip to content

Commit

Permalink
Merge pull request #2165 from simov/fix-http-throw
Browse files Browse the repository at this point in the history
Check for self.req existence inside the write method
  • Loading branch information
simov committed Apr 14, 2016
2 parents 579c111 + 1460d00 commit d5e2703
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion request.js
Expand Up @@ -1382,7 +1382,9 @@ Request.prototype.write = function () {
if (!self._started) {
self.start()
}
return self.req.write.apply(self.req, arguments)
if (self.req) {
return self.req.write.apply(self.req, arguments)
}
}
Request.prototype.end = function (chunk) {
var self = this
Expand Down
19 changes: 18 additions & 1 deletion tests/test-headers.js
Expand Up @@ -162,7 +162,7 @@ tape('undefined headers', function(t) {
})
})

tape('catch invalid characters error', function(t) {
tape('catch invalid characters error - GET', function(t) {
request({
url: s.url + '/headers.json',
headers: {
Expand All @@ -177,6 +177,23 @@ tape('catch invalid characters error', function(t) {
})
})

tape('catch invalid characters error - POST', function(t) {
request({
method: 'POST',
url: s.url + '/headers.json',
headers: {
'test': 'אבגד'
},
body: 'beep'
}, function(err, res, body) {
t.equal(err.message, 'The header content contains invalid characters')
})
.on('error', function (err) {
t.equal(err.message, 'The header content contains invalid characters')
t.end()
})
})

tape('cleanup', function(t) {
s.close(function() {
t.end()
Expand Down

0 comments on commit d5e2703

Please sign in to comment.