const {parseResponse} = require('parse-raw-http');
const data = new Buffer([
'HTTP/1.1 200 OK\r\n',
'Content-Type: text/plain; charset=utf-8\r\n',
'Transfer-Encoding: chunked\r\n',
'\r\n',
'4\r\n', 'Foo\n',
'1a\r\n', 'Chunk with 1a=16+10 bytes\n',
].join(''), 'utf8');
const res = parseResponse(data, {
decodeContentEncoding: true,
});
// Response object:
res.statusCode // 200
res.statusMessage // 'OK'
res.headers // {'content-type': '...', ...}
res.bodyData // Buffer: decoded response body
-
"Explicit is better than implicit" and "In the face of ambiguity, refuse the temptation to guess"
-
I think the aspects involved must not be unknown unknowns for you if you're parsing raw HTTP. You need to know these aspects exist and explicitly decide what you want.
They're a start. Pull requests welcome.
Before changing the major semver from 0, we'll also be testing on a massive subset of the Common Crawl WARC files, with the results cross-checked with those of running nodejs's HTTP C library on the same input.