circu.js
    Preparing search index...

    HTTP Parser for requests and responses

    const { Parser, REQUEST } = import.meta.use('http');

    // Parse a simple HTTP request
    const parser = new Parser(REQUEST);
    const buf = new TextEncoder().encode(
    'GET /api/data HTTP/1.1\r\n' +
    'Host: example.com\r\n' +
    '\r\n'
    );

    const result = parser.execute(buf);
    console.log(`Consumed ${result.bytesConsumed} bytes`);
    Index

    Constructors

    Properties

    onBody: HttpCallback | undefined
    onChunkComplete: HttpCallback | undefined
    onChunkHeader: HttpCallback | undefined
    onHeaderField: HttpCallback | undefined
    onHeadersComplete: HttpCallback | undefined
    onHeaderValue: HttpCallback | undefined
    onMessageBegin: HttpCallback | undefined
    onMessageComplete: HttpCallback | undefined
    onStatus: HttpCallback | undefined
    onUrl: HttpCallback | undefined

    Accessors

    Methods

    • Process a buffer of HTTP data

      Parameters

      Returns ParserExecuteResult

      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"
    • Pause parsing (useful for backpressure)

      Returns void

    • Reset parser state for a new message

      Parameters

      • Optionaltype: 0 | 1

        Optionally change parser type

      Returns void

    • Resume a paused parser

      Returns void