Http2ServerResponse

This object is created internally by an HTTP server, not by the user. It is passed as the second parameter to the 'request' event.

Since

v8.4.0

Constructors

Link copied to clipboard
constructor(stream: ServerHttp2Stream)

Properties

Link copied to clipboard
open val _construct: (callback: (<Error class: unknown class>?) -> Unit) -> Unit?
Link copied to clipboard
open val _writev: (chunks: Array<WritableWritevChunksItem>, callback: (<Error class: unknown class>?) -> Unit) -> Unit?
Link copied to clipboard
open val closed: Boolean

Is true after 'close' has been emitted.

Link copied to clipboard
open override val closeEvent: EventInstance<<Error class: unknown class>>
Link copied to clipboard

See response.socket.

Link copied to clipboard
open var destroyed: Boolean

Is true after writable.destroy() has been called.

Link copied to clipboard
open override val drainEvent: EventInstance<<Error class: unknown class>>
Link copied to clipboard
open val errored: <Error class: unknown class>?

Returns error if the stream has been destroyed with an error.

Link copied to clipboard
open override val errorEvent: EventInstance<<Error class: unknown class><<Error class: unknown class>>>
Link copied to clipboard

Boolean value that indicates whether the response has completed. Starts as false. After response.end() executes, the value will be true.

Link copied to clipboard
open override val finishEvent: EventInstance<<Error class: unknown class>>
Link copied to clipboard

True if headers were sent, false otherwise (read-only).

Link copied to clipboard
open override val pipeEvent: EventInstance<<Error class: unknown class><Readable>>
Link copied to clipboard

Is true if it is safe to call writable.write(), which means the stream has not been destroyed, errored, or ended.

Link copied to clipboard

A reference to the original HTTP2 request object.

Link copied to clipboard

When true, the Date header will be automatically generated and sent in the response if it is not already present in the headers. Defaults to true.

Link copied to clipboard
val socket: Any

Returns a Proxy object that acts as a net.Socket (or tls.TLSSocket) but applies getters, setters, and methods based on HTTP/2 logic.

Link copied to clipboard

When using implicit headers (not calling response.writeHead() explicitly), this property controls the status code that will be sent to the client when the headers get flushed.

Link copied to clipboard

Status message is not supported by HTTP/2 (RFC 7540 8.1.2.4). It returns an empty string.

Link copied to clipboard

The Http2Stream object backing the response.

Link copied to clipboard
open override val unpipeEvent: EventInstance<<Error class: unknown class><Readable>>
Link copied to clipboard
open override var writable: Boolean
Link copied to clipboard

Number of times writable.uncork() needs to be called in order to fully uncork the stream.

Link copied to clipboard

Is true after writable.end() has been called. This property does not indicate whether the data has been flushed, for this use writable.writableFinished instead.

Link copied to clipboard

Is set to true immediately before the 'finish' event is emitted.

Link copied to clipboard

Return the value of highWaterMark passed when creating this Writable.

Link copied to clipboard

This property contains the number of bytes (or objects) in the queue ready to be written. The value provides introspection data regarding the status of the highWaterMark.

Link copied to clipboard

Is true if the stream's buffer has been full and stream will emit 'drain'.

Link copied to clipboard

Getter for the property objectMode of a given Writable stream.

Functions

Link copied to clipboard
open fun _destroy(error: <Error class: unknown class>?, callback: (<Error class: unknown class>?) -> Unit)
Link copied to clipboard
open fun _final(callback: (<Error class: unknown class>?) -> Unit)
Link copied to clipboard
open fun _write(chunk: Any?, encoding: BufferEncoding, callback: (<Error class: unknown class>?) -> Unit)
Link copied to clipboard
fun addListener(type: EventType, listener: EventListener)

Alias for emitter.on(eventName, listener).

open override fun addListener(event: <Error class: unknown class>, listener: Function<Unit>)
open override fun addListener(event: String, listener: Function<Unit>)

Event emitter The defined events on documents including:

Link copied to clipboard

This method adds HTTP trailing headers (a header but at the end of the message) to the response.

Link copied to clipboard
fun appendHeader(name: String, value: <Error class: unknown class><String>)
fun appendHeader(name: String, value: String)

Append a single header value to the header object.

Link copied to clipboard
fun <T : ReadableStream> compose(stream: T, options: StreamComposeOptions = definedExternally): T
fun <T : ReadableStream> compose(stream: <Error class: unknown class><T>, options: StreamComposeOptions = definedExternally): T
fun <T : ReadableStream> compose(stream: <Error class: unknown class><T>, options: StreamComposeOptions = definedExternally): T
fun <T : ReadableStream> compose(stream: ComposeFnParam, options: StreamComposeOptions = definedExternally): T
Link copied to clipboard
open fun cork()

The writable.cork() method forces all written data to be buffered in memory. The buffered data will be flushed when either the {@link uncork} or {@link end} methods are called.

Link copied to clipboard
fun createPushResponse(headers: OutgoingHttpHeaders, callback: (<Error class: unknown class>?, res: Http2ServerResponse<*>) -> Unit)

Call http2stream.pushStream() with the given headers, and wrap the given Http2Stream on a newly created Http2ServerResponse as the callback parameter if successful. When Http2ServerRequest is closed, the callback is called with an error ERR_HTTP2_INVALID_STREAM.

Link copied to clipboard
open fun destroy()

Destroy the stream. Optionally emit an 'error' event, and emit a 'close' event (unless emitClose is set to false). After this call, the writable stream has ended and subsequent calls to write() or end() will result in an ERR_STREAM_DESTROYED error. This is a destructive and immediate way to destroy a stream. Previous calls to write() may not have drained, and may trigger an ERR_STREAM_DESTROYED error. Use end() instead of destroy if data should flush before close, or wait for the 'drain' event before destroying the stream.

open fun destroy(error: <Error class: unknown class>)
Link copied to clipboard
open override fun emit(event: <Error class: unknown class>, vararg args: Any?): Boolean
open override fun emit(event: String, vararg args: Any?): Boolean

Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.

Link copied to clipboard
open override fun end(cb: () -> Unit)

This method signals to the server that all of the response headers and body have been sent; that server should consider this message complete. The method, response.end(), MUST be called on each response.

open override fun end(data: <Error class: unknown class><out <Error class: unknown class>>, cb: () -> Unit)
open override fun end(data: String, cb: () -> Unit)
override fun end(str: <Error class: unknown class><out <Error class: unknown class>>, encoding: BufferEncoding, cb: () -> Unit = definedExternally)
open override fun end(str: String, encoding: BufferEncoding, cb: () -> Unit)
Link copied to clipboard

Returns an array listing the events for which the emitter has registered listeners. The values in the array are strings or Symbols.

Link copied to clipboard
fun getHeader(name: String): String

Reads out a header that has already been queued but not sent to the client. The name is case-insensitive.

Link copied to clipboard
fun getHeaderNames(): <Error class: unknown class><String>

Returns an array containing the unique names of the current outgoing headers. All header names are lowercase.

Link copied to clipboard

Returns a shallow copy of the current outgoing headers. Since a shallow copy is used, array values may be mutated without additional calls to various header-related http module methods. The keys of the returned object are the header names and the values are the respective header values. All header names are lowercase.

Link copied to clipboard

Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to {@link EventEmitter.defaultMaxListeners}.

Link copied to clipboard

Returns true if the header identified by name is currently set in the outgoing headers. The header name matching is case-insensitive.

Link copied to clipboard
fun listenerCount(type: EventType, listener: EventListener = definedExternally): Double

Returns the number of listeners listening for the event named eventName. If listener is provided, it will return how many times the listener is found in the list of the listeners of the event.

Link copied to clipboard

Returns a copy of the array of listeners for the event named eventName.

Link copied to clipboard
fun off(type: EventType, listener: EventListener)

Alias for emitter.removeListener().

Link copied to clipboard
fun on(type: EventType, listener: EventListener)

Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

open override fun on(event: <Error class: unknown class>, listener: Function<Unit>)
open override fun on(event: String, listener: Function<Unit>)
Link copied to clipboard
fun once(type: EventType, listener: EventListener)

Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

open override fun once(event: <Error class: unknown class>, listener: Function<Unit>)
open override fun once(event: String, listener: Function<Unit>)
Link copied to clipboard
fun <T : WritableStream> pipe(destination: T, options: StreamPipeOptions = definedExternally): T
Link copied to clipboard

Adds the listener function to the beginning of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

open override fun prependListener(event: <Error class: unknown class>, listener: Function<Unit>)
open override fun prependListener(event: String, listener: Function<Unit>)
Link copied to clipboard

Adds a one-timelistener function for the event named eventName to the beginning of the listeners array. The next time eventName is triggered, this listener is removed, and then invoked.

open override fun prependOnceListener(event: <Error class: unknown class>, listener: Function<Unit>)
open override fun prependOnceListener(event: String, listener: Function<Unit>)
Link copied to clipboard

Returns a copy of the array of listeners for the event named eventName, including any wrappers (such as those created by .once()).

Link copied to clipboard
fun removeAllListeners(type: EventType = definedExternally)

Removes all listeners, or those of the specified eventName.

Link copied to clipboard
fun removeHeader(name: String)

Removes a header that has been queued for implicit sending.

Link copied to clipboard
fun removeListener(type: EventType, listener: EventListener)

Removes the specified listener from the listener array for the event named eventName.

open fun removeListener(event: <Error class: unknown class>, listener: Function<Unit>)
open fun removeListener(event: String, listener: Function<Unit>)
Link copied to clipboard

The writable.setDefaultEncoding() method sets the default encoding for a Writable stream.

Link copied to clipboard
fun setHeader(name: String, value: <Error class: unknown class><String>)
fun setHeader(name: String, value: Double)
fun setHeader(name: String, value: String)

Sets a single header value for implicit headers. If this header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings here to send multiple headers with the same name.

Link copied to clipboard

By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) to indicate an unlimited number of listeners.

Link copied to clipboard
fun setTimeout(msecs: Number, callback: () -> Unit = definedExternally)

Sets the Http2Stream's timeout value to msecs. If a callback is provided, then it is added as a listener on the 'timeout' event on the response object.

Link copied to clipboard
open fun uncork()

The writable.uncork() method flushes all data buffered since {@link cork} was called.

Link copied to clipboard
override fun write(    chunk: <Error class: unknown class><out <Error class: unknown class>>,     callback: (<Error class: unknown class>) -> Unit = definedExternally): Boolean
override fun write(chunk: String, callback: (<Error class: unknown class>) -> Unit = definedExternally): Boolean

If this method is called and response.writeHead() has not been called, it will switch to implicit header mode and flush the implicit headers.

override fun write(    chunk: <Error class: unknown class><out <Error class: unknown class>>,     encoding: BufferEncoding,     callback: (<Error class: unknown class>) -> Unit = definedExternally): Boolean
override fun write(chunk: String, encoding: BufferEncoding, callback: (<Error class: unknown class>) -> Unit = definedExternally): Boolean
Link copied to clipboard

Sends a status 100 Continue to the client, indicating that the request body should be sent. See the 'checkContinue' event on Http2Server and Http2SecureServer.

Link copied to clipboard
fun writeEarlyHints(hints: <Error class: unknown class><String, Any>)

Sends a status 103 Early Hints to the client with a Link header, indicating that the user agent can preload/preconnect the linked resources. The hints is an object containing the values of headers to be sent with early hints message.

Link copied to clipboard
fun writeHead(statusCode: Number, headers: OutgoingHttpHeaders = definedExternally)

Sends a response header to the request. The status code is a 3-digit HTTP status code, like 404. The last argument, headers, are the response headers.

fun writeHead(statusCode: Number, statusMessage: String, headers: OutgoingHttpHeaders = definedExternally)