Server request class.

Hierarchy

Constructors

Properties

_cookies: undefined | Record<string, string> = undefined
_form: undefined | Params = undefined
_ip: undefined | null | string = undefined
_protocol: undefined | string = undefined
_query: undefined | Params = undefined
_stream: Readable
_userinfo: undefined | null | string = undefined
autoDecompress: boolean = true

Automatically decompress message body if necessary.

basePath: string = ''

Request base path.

headers: Headers

HTTP headers.

isSecure: boolean

Check if underlying socket was encrypted with TLS.

isWebSocket: boolean

Request is a WebSocket handshake.

method: null | string

Request method.

path: string = '/'

Request path.

remoteAddress: null | string

Peer address.

requestId: string

Request ID.

reverseProxy: boolean

Reverse proxy support is activated.

url: null | string

Request URL.

Accessors

  • get _params(): Params
  • Returns Params

  • get baseURL(): string
  • Server base URL.

    Returns string

  • get ip(): null | string
  • Remote IP address. Uses he X-Forwarded-For header value if reverse proxy support is activated.

    Returns null | string

  • get protocol(): string
  • Request protocol. Uses the X-Forwarded-Proto header value if reverse proxy support is activated.

    Returns string

  • get query(): Params
  • Query parameters.

    Returns Params

  • get userinfo(): null | string
  • User info.

    Returns null | string

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 cookie value.

    Parameters

    • name: string

    Returns null | string

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

  • 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