Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HttpServerResponse

Represents a server-side HTTP response.

An instance of this is created and associated to every instance of HttpServerRequest that.

It allows the developer to control the HTTP response that is sent back to the client for a particular HTTP request.

It contains methods that allow HTTP headers and trailers to be set, and for a body to be written out to the response.

It also allows files to be streamed by the kernel directly from disk to the outgoing HTTP connection, bypassing user space altogether (where supported by the underlying operating system). This is a very efficient way of serving files from the server since buffers do not have to be read one by one from the file and written to the outgoing socket.

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

Hierarchy

  • HttpServerResponse

Implements

Index

Methods

addCookie

  • Add a cookie. This will be sent back to the client in the response.

    Parameters

    Returns HttpServerResponse

bodyEndHandler

  • Provides a handler that will be called after the last part of the body is written to the wire. The handler is called asynchronously of when the response has been received by the client. This provides a hook allowing you to do more operations once the request has been sent over the wire such as resource cleanup.

    Parameters

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

    Returns HttpServerResponse

bytesWritten

  • bytesWritten(): number
  • Returns number

close

  • close(): void
  • Close the underlying TCP connection corresponding to the request.

    Returns void

closeHandler

  • Set a close handler for the response, this is called when the underlying connection is closed and the response was still using the connection.

    For HTTP/1.x it is called when the connection is closed before end() is called, therefore it is not guaranteed to be called.

    For HTTP/2 it is called when the related stream is closed, and therefore it will be always be called.

    Parameters

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

    Returns HttpServerResponse

closed

  • closed(): boolean
  • Returns boolean

drainHandler

  • Parameters

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

    Returns HttpServerResponse

end

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

    Returns PromiseLike<void>

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

    Parameters

    Returns void

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

    Parameters

    • chunk: string

    Returns PromiseLike<void>

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

    Parameters

    Returns void

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

    Parameters

    • chunk: string
    • enc: string

    Returns PromiseLike<void>

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

    Parameters

    Returns void

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

    Parameters

    Returns PromiseLike<void>

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

    Parameters

    Returns void

endHandler

  • Set an end handler for the response. This will be called when the response is disposed to allow consistent cleanup of the response.

    Parameters

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

    Returns HttpServerResponse

ended

  • ended(): boolean
  • Returns boolean

exceptionHandler

getStatusCode

  • getStatusCode(): number
  • Returns number

getStatusMessage

  • getStatusMessage(): string
  • Returns string

headWritten

  • headWritten(): boolean
  • Returns boolean

headers

  • Returns MultiMap

headersEndHandler

  • Provide a handler that will be called just before the headers are written to the wire.

    This provides a hook allowing you to add any more headers or do any more operations before this occurs.

    Parameters

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

    Returns HttpServerResponse

isChunked

  • isChunked(): boolean
  • Returns boolean

push

  • Like {@link HttpServerResponse#push} with no headers.

    Parameters

    Returns PromiseLike<HttpServerResponse>

  • Like {@link HttpServerResponse#push} with no headers.

    Parameters

    Returns HttpServerResponse

  • Like {@link HttpServerResponse#push} with the host copied from the current request.

    Parameters

    Returns PromiseLike<HttpServerResponse>

  • Like {@link HttpServerResponse#push} with the host copied from the current request.

    Parameters

    Returns HttpServerResponse

  • Like {@link HttpServerResponse#push} with the host copied from the current request.

    Parameters

    Returns PromiseLike<HttpServerResponse>

  • Like {@link HttpServerResponse#push} with the host copied from the current request.

    Parameters

    Returns HttpServerResponse

  • Push a response to the client.

    The handler will be notified with a success when the push can be sent and with a failure when the client has disabled push or reset the push before it has been sent.

    The handler may be queued if the client has reduced the maximum number of streams the server can push concurrently.

    Push can be sent only for peer initiated streams and if the response is not ended.

    Parameters

    Returns PromiseLike<HttpServerResponse>

  • Push a response to the client.

    The handler will be notified with a success when the push can be sent and with a failure when the client has disabled push or reset the push before it has been sent.

    The handler may be queued if the client has reduced the maximum number of streams the server can push concurrently.

    Push can be sent only for peer initiated streams and if the response is not ended.

    Parameters

    Returns HttpServerResponse

putHeader

  • Put an HTTP header

    Parameters

    • name: string
    • value: string

    Returns HttpServerResponse

  • Like {@link HttpServerResponse#putHeader} but using CharSequence

    Parameters

    • name: string
    • value: string

    Returns HttpServerResponse

  • Like {@link HttpServerResponse#putHeader} but providing multiple values via a String Iterable

    Parameters

    • name: string
    • values: any

    Returns HttpServerResponse

  • Like {@link HttpServerResponse#putHeader} but with CharSequence Iterable

    Parameters

    • name: string
    • values: any

    Returns HttpServerResponse

putTrailer

  • Put an HTTP trailer

    Parameters

    • name: string
    • value: string

    Returns HttpServerResponse

  • Like {@link HttpServerResponse#putTrailer} but using CharSequence

    Parameters

    • name: string
    • value: string

    Returns HttpServerResponse

  • Like {@link HttpServerResponse#putTrailer} but providing multiple values via a String Iterable

    Parameters

    • name: string
    • values: any

    Returns HttpServerResponse

  • Like {@link HttpServerResponse#putTrailer} but with CharSequence Iterable

    Parameters

    • name: string
    • value: any

    Returns HttpServerResponse

removeCookie

  • removeCookie(name: string): Cookie | null
  • removeCookie(name: string, invalidate: boolean): Cookie | null
  • removeCookie(name: string, domain: string, path: string): Cookie | null
  • removeCookie(name: string, domain: string, path: string, invalidate: boolean): Cookie | null
  • Expire a cookie, notifying a User Agent to remove it from its cookie jar.

    NOTE: This method will only remove the first occurrence of the given name. Users probably may want to use: {@link HttpServerResponse#removeCookies}

    Parameters

    • name: string

    Returns Cookie | null

  • Remove a cookie from the cookie set. If invalidate is true then it will expire a cookie, notifying a User Agent to remove it from its cookie jar.

    NOTE: This method will only expire the first occurrence of the given name. Users probably may want to use: {@link HttpServerResponse#removeCookies}

    Parameters

    • name: string
    • invalidate: boolean

    Returns Cookie | null

  • Expires a cookie from the cookie set. This will notify a User Agent to remove it from its cookie jar.

    Parameters

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

    Returns Cookie | null

  • Remove a cookie from the cookie set. If invalidate is true then it will expire a cookie, notifying a User Agent to remove it from its cookie jar.

    Parameters

    • name: string
    • domain: string
    • path: string
    • invalidate: boolean

    Returns Cookie | null

removeCookies

  • removeCookies(name: string): Cookie
  • removeCookies(name: string, invalidate: boolean): Cookie
  • Expire all cookies, notifying a User Agent to remove it from its cookie jar.

    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

  • Remove all cookies from the cookie set. If invalidate is true then it will expire a cookie, notifying a User Agent to remove it from its cookie jar.

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

    Parameters

    • name: string
    • invalidate: boolean

    Returns Cookie

reset

  • reset(): boolean
  • reset(code: number): boolean
  • Reset this HTTP/2 stream with the error code 0.

    Returns boolean

  • Reset this response:

    • for HTTP/2, send an HTTP/2 reset frame with the specified error code
    • for HTTP/1.x, close the connection when the current response has not yet been sent

    When the response has already been sent nothing happens and false is returned as indicator.

    Parameters

    • code: number

    Returns boolean

send

  • Send the request with an empty body.

    Returns PromiseLike<void>

  • Send the request with an empty body.

    Parameters

    Returns void

  • Send the request with a string body.

    Parameters

    • body: string

    Returns PromiseLike<void>

  • Send the request with a string body.

    Parameters

    Returns void

  • Send the request with a buffer body.

    Parameters

    Returns PromiseLike<void>

  • Send the request with a buffer body.

    Parameters

    Returns void

  • Send the request with a stream body.

    If the CONTENT_LENGTH is set then the request assumes this is the length of the {stream}, otherwise the request will set a chunked CONTENT_ENCODING.

    Parameters

    Returns PromiseLike<void>

  • Send the request with a stream body.

    If the CONTENT_LENGTH is set then the request assumes this is the length of the {stream}, otherwise the request will set a chunked CONTENT_ENCODING.

    Parameters

    Returns void

sendFile

  • Like {@link HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been completely written to the wire.

    Parameters

    • filename: string

    Returns PromiseLike<void>

  • Like {@link HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been completely written to the wire.

    Parameters

    Returns HttpServerResponse

  • Like {@link HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been completely written to the wire.

    Parameters

    • filename: string
    • offset: number

    Returns PromiseLike<void>

  • Like {@link HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been completely written to the wire.

    Parameters

    Returns HttpServerResponse

  • Like {@link HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been completely written to the wire.

    Parameters

    • filename: string
    • offset: number
    • length: number

    Returns PromiseLike<void>

  • Like {@link HttpServerResponse#sendFile} but providing a handler which will be notified once the file has been completely written to the wire.

    Parameters

    Returns HttpServerResponse

setChunked

  • If chunked is true, this response will use HTTP chunked encoding, and each call to write to the body will correspond to a new HTTP chunk sent on the wire.

    If chunked encoding is used the HTTP header Transfer-Encoding with a value of Chunked will be automatically inserted in the response.

    If chunked is false, this response will not use HTTP chunked encoding, and therefore the total size of any data that is written in the respone body must be set in the Content-Length header before any data is written out.

    An HTTP chunked response is typically used when you do not know the total size of the request body up front.

    Parameters

    • chunked: boolean

    Returns HttpServerResponse

setStatusCode

  • Set the status code. If the status message hasn't been explicitly set, a default status message corresponding to the code will be looked-up and used.

    Parameters

    • statusCode: number

    Returns HttpServerResponse

setStatusMessage

  • Set the status message

    Parameters

    • statusMessage: string

    Returns HttpServerResponse

setStreamPriority

  • Sets the priority of the associated stream

    This is not implemented for HTTP/1.x.

    Parameters

    Returns HttpServerResponse

setWriteQueueMaxSize

streamId

  • streamId(): number
  • Returns number

trailers

  • Returns MultiMap

write

  • Same as but with an handler called when the operation completes

    Parameters

    Returns PromiseLike<void>

  • Same as but with an handler called when the operation completes

    Parameters

    Returns void

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

    Parameters

    • chunk: string
    • enc: string

    Returns PromiseLike<void>

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

    Parameters

    Returns void

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

    Parameters

    • chunk: string

    Returns PromiseLike<void>

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

    Parameters

    Returns void

writeContinue

  • Used to write an interim 100 Continue response to signify that the client should send the rest of the request. Must only be used if the request contains an "Expect:100-Continue" header

    Returns HttpServerResponse

writeCustomFrame

  • Write an HTTP/2 frame to the response, allowing to extend the HTTP/2 protocol.

    The frame is sent immediatly and is not subject to flow control.

    Parameters

    • type: number
    • flags: number
    • payload: Buffer

    Returns HttpServerResponse

  • Like {@link HttpServerResponse#writeCustomFrame} but with an HttpFrame.

    Parameters

    Returns HttpServerResponse

writeEarlyHints

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

    Parameters

    Returns PromiseLike<void>

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

    Parameters

    Returns void

writeQueueFull

  • writeQueueFull(): boolean
  • This will return true if there are more bytes in the write queue than the value set using {@link HttpServerResponse#setWriteQueueMaxSize}

    Returns boolean

Generated using TypeDoc