HTTP message body base class.

Hierarchy

Constructors

  • Parameters

    • headers: string[]
    • stream: Readable

    Returns Body

Properties

_form: undefined | Params = undefined
_stream: Readable
autoDecompress: boolean = true

Automatically decompress message body if necessary.

headers: Headers

HTTP headers.

Accessors

  • get _params(): Params
  • Returns Params

Methods

  • Returns AsyncIterable<Buffer>

  • Returns Promise<Uint8Array[]>

  • Parameters

    Returns FormIterator

  • Returns boolean

  • Get message body as Buffer object.

    Returns Promise<Buffer>

  • Get message body as a readable stream.

    Returns Readable

  • Get async iterator for uploaded files from message body.

    Parameters

    Returns AsyncIterableIterator<FileUpload>

    Example

    // Iterate over uploaded files
    for await (const {fieldname, file, filename} of body.files()) {
    const parts = [];
    for await (const chunk of file) {
    parts.push(chunk);
    }
    const content = Buffer.concat(parts).toString();
    console.write(`${fieldname}: ${content}`);
    }
  • Get form parameters from message body.

    Parameters

    Returns Promise<Params>

    Example

    // Get a specific parameter
    const params = await body.form();
    const foo = params.get('foo');
  • Get HTTP header from message.

    Parameters

    • name: string

    Returns null | string

    Example

    // Get User-Agent header
    const agent = body.get('User-Agent');
  • Get HTML message body as @mojojs/dom object.

    Returns Promise<default>

  • Get JSON message body as parsed data structure.

    Type Parameters

    Returns Promise<T>

  • Pipe message body to writable stream.

    Parameters

    • writer: Writable

    Returns Promise<void>

  • Set HTTP header for message. // Set Server header body.set('Server', 'mojo.js');

    Parameters

    • name: string
    • value: string

    Returns Body

  • Get message body as string.

    Parameters

    • charset: BufferEncoding = 'utf8'

    Returns Promise<string>

  • Get XML message body as @mojojs/dom object.

    Returns Promise<default>

  • Get YAML message body as parsed data structure.

    Returns Promise<unknown>

Generated using TypeDoc