Handling Invalid Response Headers

256 views
Skip to first unread message

Rob Wilkerson

unread,
Dec 8, 2015, 7:58:46 PM12/8/15
to nodejs
I have a situation where I have some code running locally that has to communicate with another device on the same network. To do so, I'm making a straight http request to http://192.168.0.1, a request that returns a bunch of data in the response body. The problem I'm having is that the device itself returns invalid headers:

HTTP/1.1 200 OK
Date: Wed, 02 Dec 2015 16:42:45 GMT
Server: nostradamus 1.9.5
Connection: close
Etag: Aug 28 2015, 07:57:20
Transfer-Encoding: chunked
HTTP/1.0 200 OK
Content-Type: text/html

Note the duplicate "HTTP/1.0 200 OK" header. Other tools (e.g. Chrome, curl, python) that I've tried at least handle the bad headers "gracefully", but node simply dies with a HPE_INVALID_HEADER_TOKEN error. It's not incorrect, of course, but I need a workaround. My code will be installed on hundreds of thousands of desktops talking to hundreds of thousands of these devices. We simply can't update all of the devices to fix the headers.

All I care about is the response body. Is there any way to get node to be more lenient and ignore the bad header? Do I have any options here?

Any thoughts would be much appreciated. I'm completely stuck here.

Jimb Esser

unread,
Dec 15, 2015, 7:54:58 PM12/15/15
to nodejs
Take a look at the NPM module http-parser-js [1], it's a drop-in replacement for the native http parser bindings.  As well as being pure JS and having better performance in some circumstances, it's also more lenient (I've used it to deal with a very similar situation of a server returning a header with no name).  I'm not completely sure it will handle your exact use case, but updating it so that it does should be easy and we'd take the PR.  If it doesn't just work, it's easy to add a new test with your raw response [2], and once it's reproduced it's easy to fix ;).

Reply all
Reply to author
Forward
0 new messages