request: request.get crashes with "The header content contains invalid characters"
Try this:
require('request').get('http://www.test.com/אבגד.pdf');
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)))
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 13
- Comments: 21 (3 by maintainers)
Thing is, while it’s easy to fix this,
requestshould catch the error and propagate it through the error handlers. Currently it’s thrown as an uncaught exception which can cause pretty bad server crashes that you can never recover from because you cannot manually try/catch this.So I’d say this is a pretty severe bug in
request. The error needs to be propagated.Turns out that in my case I was sending a line break on a cookie. I had to remove it.
Just in case someone else had the same issue as I did - I had this error with the
aws-sdkand it was driving me crazy for hours. Turned out to be aPrvScancharacter\u001b[5~that for some reason was lurking about in my~/.aws/credentialsfile, which propagated into the Authorization header used by AWS requests. The error only appeared on my Windows 7 machine, so it was probably something with how the credentials file was retrieved from my AWS account and some Windows character encoding. It wasn’t visible whencating the credentials file either, but became visible once I opened the file withvi.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 ?!
Also - I found no way to catch that exception. No matter if there’s a try-catch, or
.on('error', ...