I am trying to parse an HTTP response in form Stringor Bufferin Object.
The result will be Object, as an answer to the native httpmodule.
I tried to import my own HTTP parser, but the results were too crude for my use:
var HTTPParser = process.binding('http_parser').HTTPParser;
var parser = new HTTPParser(HTTPParser.RESPONSE);
parser.onHeadersComplete = function(res) {
console.log('onHeadersComplete');
console.log(res);
};
parser.execute(data, 0, data.length);
which will return something like this:
onHeadersComplete
{
headers:
[ 'X-Powered-By',
'Express',
'Content-Type',
'text/plain',
'Content-Length',
'2',
'Date',
'Sat, 19 Apr 2014 20:16:45 GMT',
'Connection',
'keep-alive' ],
statusCode: 200,
versionMajor: 1,
versionMinor: 1,
shouldKeepAlive: true,
upgrade: false
}
For my use case, two things are missing:
- display header names associated with header values
body analysis response
- Does anyone know how to achieve this?
Thank you in advance for your help!
source
share