Possible to use http-parser-js in an Electron app?


#1

I need to make an HTTP request to a service that returns malformed headers that the native Node.js parser can’t handle. In a test script, I’ve found that I can use the http-parser-js library to make the same request and it handles the bad headers gracefully.

Now I need to make that work within the Electron app that needs to actually make the call and retrieve the data and it’s failing with the same HPE_INVALID_HEADER_TOKEN. I assume, for that reason, that the native HTTP parser is not getting overridden.

In my electron app, I have the same code I used in my test script:

process.binding('http_parser').HTTPParser = require('http-parser-js').HTTPParser;
var http = require('http');

var req = http.request( ... )

Is there an alternate process binding syntax I can use within Electron?


#2

This was not an electron issue. My app makes several different requests and most of the are to services that return proper headers. Originally, I was using the request-promise library to handle all calls, but I needed to modify the one call that returned bad headers.

The problem was that I was still using request-promise for the other calls and that library conflicts with the custom code I had to write to deal with the malformed headers. Once I modified my custom code to handle all requests, things worked much more smoothly.