Optionaltype: 0 | 1Parser type: REQUEST (0) or RESPONSE (1). Defaults to RESPONSE.
Get current parser state
Process a buffer of HTTP data
const { Parser, RESPONSE } = import.meta.use('http');
const parser = new Parser(RESPONSE);
let body = '';
parser.onBody = (buf, off, len) => {
body += new TextDecoder().decode(
buf.slice(off, off + len)
);
};
const data = new TextEncoder().encode(
'HTTP/1.1 200 OK\r\n' +
'Content-Length: 5\r\n\r\n' +
'hello'
);
const res = parser.execute(data);
console.log(body); // "hello"
Signal EOF to the parser
Pause parsing (useful for backpressure)
Reset parser state for a new message
Optionaltype: 0 | 1Optionally change parser type
Resume a paused parser
HTTP Parser for requests and responses
Example