I when to get the raw response include http status line and http raw headers.
expected like the curl -i --raw
output
u@l:/# curl -i --raw https://httpbin.org/ip
HTTP/1.1 200 OK
Connection: keep-alive
Server: meinheld/0.6.1
Date: Wed, 30 Aug 2017 16:36:59 GMT
Content-Type: application/json
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
X-Powered-By: Flask
X-Processed-Time: 0.000962972640991
Content-Length: 31
Via: 1.1 vegur
{
"origin": "11.52.71.4"
}
Now I Stitching string like this
const request = require('request');
request('https://httpbin.org/get', function (err, rsp, body) {
var headers = '';
for (var i = 0; i < rsp.rawHeaders.length; i++) {
headers += rsp.rawHeaders[i] + (i % 2 ? '\r\n' : ': ');
}
console.log('HTTP/' + rsp.httpVersion + ' ' + rsp.statusCode + ' ' + rsp.statusMessage
+ '\r\n' + headers + '\r\n' + rsp.body);
});
It's work, but is there easy way to get the rawResponse?