User-agent response class.

Hierarchy

  • Body
    • UserAgentResponse

Constructors

Properties

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

Automatically decompress message body if necessary.

headers: Headers

HTTP headers.

httpVersion: string

HTTP version.

statusCode: number

Response status code.

statusMessage: string

Response status message.

Accessors

  • get _params(): Params
  • Returns Params

  • get isClientError(): boolean
  • Check if response has a 4xx response status code.

    Returns boolean

  • get isError(): boolean
  • Check if response has a 4xx or 5xx response status code.

    Returns boolean

  • get isRedirect(): boolean
  • Check if response has a 3xx response status code.

    Returns boolean

  • get isServerError(): boolean
  • Check if response has a 5xx response status code.

    Returns boolean

  • get isSuccess(): boolean
  • Check if response has a 2xx response status code.

    Returns boolean

  • get type(): null | string
  • Get Content-Type header value.

    Returns null | string

Methods

  • Returns AsyncIterable<Buffer>

  • Returns Promise<Uint8Array[]>

  • Parameters

    Returns AsyncIterableIterator<[string, Readable, string, string, string]>

  • 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 UserAgentResponse

  • 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