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
request.get crashes with "The header content contains invalid characters" #2120
Comments
Also - I found no way to catch that exception. No matter if there's a try-catch, or |
I'm getting the same error using Node version 0.12.12 and greater. The same code works with 0.12.9:
|
Turns out that in my case I was sending a line break on a cookie. I had to remove it. |
No, my case is a simple one-liner, no cookies, no additional headers. |
I get the same issue , using https://github.com/matt-major/do-wrapper when trying to access my account information.
|
Thing is, while it's easy to fix this, So I'd say this is a pretty severe bug in |
I've invested a good 2h now trying to fix this issue, for which writing a reproducing test case was pretty trivial.
To be blunt, it scares me that my production services rely on a library with a 1.4k line main file in which the logic is so convoluted that something as easy as propagating an error from a try/catch is practically impossible without deeply studying the entire rube goldberg machine of events. Time to move away from this. |
This also affects Node 5.6.0 and above which has more strict header validation: https://github.com/nodejs/node/blob/v5.6.0/CHANGELOG.md |
Fixed here #2164 Take a look at the test on how to handle the error in your code. |
Seems like handling the error is as usual, with an This will make the |
Well, now I feel like an incredibly silly prick. My apologies, next time I'll just publish my branch and ask for feedback. |
@TimBeyer no problem, version 2.71 is published with the fix 👍 |
@simov The version 2.71 has fixed the problem partially for me, Here is my scenario I am sending a post request and getting data as chunks, request({
method: 'POST',
headers: {
'test': 'אבגד'
},
uri: apiUrl,
qs: req.query,
json: req.body,
gzip: true
}
, function(error, response, body) {
console.log('callback')
})
.on('response', function (response) {
console.log(response)
})
.on('error', function (err) {
console.log(err);
}); When I run this I get an error return self.req.write.apply(self.req, arguments)
^
TypeError: Cannot read property 'write' of undefined
at Request.write (/Users/muhammadkhurrumqureshi/Workspace/www/node_modules/request/request.js:1385:18)
at end (/Users/muhammadkhurrumqureshi/Workspace/www/node_modules/request/request.js:565:18)
at Immediate._onImmediate (/Users/muhammadkhurrumqureshi/Workspace/www/node_modules/request/request.js:594:7)
at processImmediate [as _immediateCallback] (timers.js:383:17) Can you kindly help on this? |
@khurrumqureshi fixed here #2165 👍 Basically the same check as in the |
@simov 👍 |
Same here.
Response headers are:
Headers of request are:
As you can see the request contains 3 times a special character Might it be that the problem? It looks like node.js |
Just in case someone else had the same issue as I did - I had this error with the |
Yeah, just had the same issue. Took me a few hours to figure it out I must admit. |
I just hit the same error and cannot find a way to catch it. I'm building an image proxy so I cannot really controll what the other server is returning. How can I avoid carshing the whole server in production ?! |
I had the same issue, it started to work when i exchange the "set" for "auth". For example:
CONSOLE RES: ERROR, Wrong GET request: After changing the code to:
CONSOLE RES: OKI ;p |
In my case: I was trying to get a token from code and when I tried to copy it from the terminal (where I was logging for testing) and pasting it in postman to test if it works, it was adding end-of-line wherever it would have a line end in the terminal so make sure you are not doing that :P |
Try this:
After a few milliseconds this crashes with
TypeError('The header content contains invalid characters')
Now if I wrap it in
encodeURI
- it succeeds.But if we receive urls from an external source - they may or may not be encoded. Is there some kind of built in mechanism to deal with this? (Other than doing
encodeURI(decodeURI(url))
)The text was updated successfully, but these errors were encountered: