Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HttpServerRequest

Represents a server-side HTTP request.

Instances are created for each request and passed to the user via a handler.

Each instance of this class is associated with a corresponding HttpServerResponse instance via {@link HttpServerRequest#response}.

It implements ReadStream so it can be used with Pipe to pipe data with flow control.

Hierarchy

  • HttpServerRequest

Implements

Index

Methods

absoluteURI

  • absoluteURI(): string
  • Returns string

body

bodyHandler

  • Convenience method for receiving the entire request body in one piece.

    This saves the user having to manually setting a data and end handler and append the chunks of the body until the whole body received. Don't use this if your request body is large - you could potentially run out of RAM.

    Parameters

    Returns HttpServerRequest

bytesRead

  • bytesRead(): number
  • Returns number

connection

  • Returns HttpConnection

cookieCount

  • cookieCount(): number
  • Returns number

cookieMap

  • cookieMap(): {}
  • Returns {}

cookies

  • Returns a read only set of parsed cookies that match the given name, or an empty set. Several cookies may share the same name but have different keys. A cookie is unique by its tuple.

    The set entries are references to the request original set. This means that performing property changes in the cookie objects will affect the original object too.

    NOTE: the returned is read-only. This means any attempt to modify (add or remove to the set), will throw UnsupportedOperationException.

    Parameters

    • name: string

    Returns Cookie

  • Returns a modifiable set of parsed cookies from the COOKIE header. Several cookies may share the same name but have different keys. A cookie is unique by its tuple.

    Request cookies are directly linked to response cookies. Any modification to a cookie object in the returned set will mark the cookie to be included in the HTTP response. Removing a cookie from the set, will also mean that it will be removed from the response, regardless if it was modified or not.

    Returns Cookie

customFrameHandler

  • Set a custom frame handler. The handler will get notified when the http stream receives an custom HTTP/2 frame. HTTP/2 permits extension of the protocol.

    Parameters

    Returns HttpServerRequest

end

  • Same as {@link HttpServerRequest#end} but with an handler called when the operation completes

    Returns PromiseLike<void>

  • Same as {@link HttpServerRequest#end} but with an handler called when the operation completes

    Parameters

    Returns void

endHandler

  • Parameters

    • endHandler: ((res: void) => void) | Handler<void> | null | undefined

    Returns HttpServerRequest

exceptionHandler

fetch

formAttributes

  • Returns a map of all form attributes in the request.

    Be aware that the attributes will only be available after the whole body has been received, i.e. after the request end handler has been called.

    {@link HttpServerRequest#setExpectMultipart} must be called first before trying to get the form attributes.

    Returns MultiMap

getCookie

  • getCookie(name: string): Cookie | null
  • getCookie(name: string, domain: string, path: string): Cookie | null
  • Get the cookie with the specified name.

    NOTE: this will return just the 1st Cookie that matches the given name, to get all cookies for this name see: {@link HttpServerRequest#cookies}

    Parameters

    • name: string

    Returns Cookie | null

  • Get the cookie with the specified .

    Parameters

    • name: string
    • domain: string
    • path: string

    Returns Cookie | null

getFormAttribute

  • getFormAttribute(attributeName: string): string | null
  • Return the first form attribute value with the specified name

    Parameters

    • attributeName: string

    Returns string | null

getHeader

  • getHeader(headerName: string): string | null
  • getHeader(headerName: string): string
  • Return the first header value with the specified name

    Parameters

    • headerName: string

    Returns string | null

  • Return the first header value with the specified name

    Parameters

    • headerName: string

    Returns string

getParam

  • getParam(paramName: string): string | null
  • getParam(paramName: string, defaultValue: string): string
  • Return the first param value with the specified name

    Parameters

    • paramName: string

    Returns string | null

  • Return the first param value with the specified name or defaultValue when the query param is not present

    Parameters

    • paramName: string
    • defaultValue: string

    Returns string

getParamsCharset

  • getParamsCharset(): string
  • Returns string

handler

headers

  • Returns MultiMap

host

  • host(): string | null
  • Returns string | null

isEnded

  • isEnded(): boolean
  • Has the request ended? I.e. has the entire request, including the body been read?

    Returns boolean

isExpectMultipart

  • isExpectMultipart(): boolean
  • Returns boolean

isSSL

  • isSSL(): boolean
  • Returns boolean

localAddress

  • Returns SocketAddress

method

  • Returns HttpMethod

params

  • Returns MultiMap

path

  • path(): string | null
  • Returns string | null

pause

pipe

  • Pause this stream and return a to transfer the elements of this stream to a destination .

    The stream will be resumed when the pipe will be wired to a WriteStream.

    Returns Pipe<Buffer>

pipeTo

  • Pipe this ReadStream to the WriteStream.

    Elements emitted by this stream will be written to the write stream until this stream ends or fails.

    Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

    Parameters

    Returns PromiseLike<void>

  • Pipe this ReadStream to the WriteStream.

    Elements emitted by this stream will be written to the write stream until this stream ends or fails.

    Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

    Parameters

    Returns void

query

  • query(): string | null
  • Returns string | null

remoteAddress

  • Returns SocketAddress

response

  • Returns HttpServerResponse

resume

routed

  • Marks this request as being routed to the given route. This is purely informational and is being provided to metrics.

    Parameters

    • route: string

    Returns HttpServerRequest

scheme

  • scheme(): string | null
  • Returns string | null

setExpectMultipart

  • Call this with true if you are expecting a multi-part body to be submitted in the request. This must be called before the body of the request has been received

    Parameters

    • expect: boolean

    Returns HttpServerRequest

setParamsCharset

  • Override the charset to use for decoding the query parameter map, when none is set, UTF8 is used.

    Parameters

    • charset: string

    Returns HttpServerRequest

sslSession

  • sslSession(): any
  • Returns any

streamId

  • streamId(): number
  • Returns number

streamPriority

  • Returns StreamPriority

streamPriorityHandler

toNetSocket

toWebSocket

  • Upgrade the connection of the current request to a WebSocket.

    This is an alternative way of handling WebSockets and can only be used if no WebSocket handler is set on the HttpServer, and can only be used during the upgrade request during the WebSocket handshake.

    Both {@link HttpServerRequest#handler} and {@link HttpServerRequest#endHandler} will be set to get the full body of the request that is necessary to perform the WebSocket handshake.

    If you need to do an asynchronous upgrade, i.e not performed immediately in your request handler, you need to {@link HttpServerRequest#pause} the request in order to not lose HTTP events necessary to upgrade the request.

    Returns PromiseLike<ServerWebSocket>

  • Upgrade the connection of the current request to a WebSocket.

    This is an alternative way of handling WebSockets and can only be used if no WebSocket handler is set on the HttpServer, and can only be used during the upgrade request during the WebSocket handshake.

    Both {@link HttpServerRequest#handler} and {@link HttpServerRequest#endHandler} will be set to get the full body of the request that is necessary to perform the WebSocket handshake.

    If you need to do an asynchronous upgrade, i.e not performed immediately in your request handler, you need to {@link HttpServerRequest#pause} the request in order to not lose HTTP events necessary to upgrade the request.

    Parameters

    Returns void

uploadHandler

  • Set an upload handler. The handler will get notified once a new file upload was received to allow you to deal with the file upload.

    Parameters

    Returns HttpServerRequest

uri

  • uri(): string
  • Returns string

version

  • Returns HttpVersion

Generated using TypeDoc