Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for self.req existence inside the write method #2165

Merged
merged 1 commit into from Apr 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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