ServerResponse

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

v0.1.17

Constructors

Link copied to clipboard
constructor(req: Request)

Properties

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

Is true after 'close' has been emitted.

Link copied to clipboard

Alias of outgoingMessage.socket.

Link copied to clipboard
open var destroyed: Boolean

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

Link copied to clipboard
open val errored: JsError?

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

Link copied to clipboard
Link copied to clipboard

Read-only. true if the headers were sent, otherwise false.

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
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Reference to the underlying socket. Usually, users will not want to access this property.

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

When using implicit headers (not calling response.writeHead() explicitly), this property controls the status message that will be sent to the client when the headers get flushed. If this is left as undefined then the standard message for the status code will be used.

Link copied to clipboard

If set to true, Node.js will check whether the Content-Length header value and the size of the body, in bytes, are equal. Mismatching the Content-Length header value will result in an Error being thrown, identified by code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'.

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: JsError?, callback: (JsError?) -> Unit)
Link copied to clipboard
open fun _final(callback: (JsError?) -> Unit)
Link copied to clipboard
open fun _write(chunk: Any?, encoding: BufferEncoding, callback: (JsError?) -> Unit)
Link copied to clipboard
open fun addListener(event: Symbol, listener: Function<Unit>)
open fun addListener(event: String, listener: Function<Unit>)
fun addListener(event: WritableEvent.DRAIN, listener: () -> Unit)
fun addListener(event: WritableEvent.ERROR, listener: (JsError) -> Unit)
fun addListener(event: WritableEvent.FINISH, listener: () -> Unit)
fun addListener(event: WritableEvent.PIPE, listener: (src: Readable) -> Unit)
fun addListener(event: WritableEvent.UNPIPE, listener: (src: Readable) -> Unit)

fun addListener(event: WritableEvent.CLOSE, listener: () -> Unit)

Event emitter The defined events on documents including:

Link copied to clipboard

Adds HTTP trailers (headers but at the end of the message) to the message.

Link copied to clipboard
fun appendHeader(name: String, value: String)

Append a single header value to the header object.

Link copied to clipboard
fun assignSocket(socket: Socket)
Link copied to clipboard
open fun <T : ReadableStream> compose(stream: T, options: StreamComposeOptions = definedExternally): T
open fun <T : ReadableStream> compose(stream: AsyncIterable<T>, options: StreamComposeOptions = definedExternally): T
open fun <T : ReadableStream> compose(stream: JsIterable<T>, options: StreamComposeOptions = definedExternally): T
open 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
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: JsError)
Link copied to clipboard
fun detachSocket(socket: Socket)
Link copied to clipboard
open fun emit(event: Symbol, vararg args: Any?): Boolean
open fun emit(event: String, vararg args: Any?): Boolean
Link copied to clipboard
open override fun end(cb: () -> Unit)

Calling the writable.end() method signals that no more data will be written to the Writable. The optional chunk and encoding arguments allow one final additional chunk of data to be written immediately before closing the stream.

open override fun end(data: Uint8Array, cb: () -> Unit)
open fun end(chunk: Any?, cb: () -> Unit = definedExternally)
open override fun end(data: String, cb: () -> Unit)
open fun end(chunk: Any?, 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

Flushes the message headers.

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

Gets the value of the HTTP header with the given name. If that header is not set, the returned value will be undefined.

Link copied to clipboard

Returns an array containing the unique names of the current outgoing headers. All 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 defaultMaxListeners}.

Link copied to clipboard

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

Link copied to clipboard
open fun on(event: Symbol, listener: Function<Unit>)
open fun on(event: String, listener: Function<Unit>)
fun on(event: WritableEvent.CLOSE, listener: () -> Unit)
fun on(event: WritableEvent.DRAIN, listener: () -> Unit)
fun on(event: WritableEvent.ERROR, listener: (JsError) -> Unit)
fun on(event: WritableEvent.FINISH, listener: () -> Unit)
fun on(event: WritableEvent.PIPE, listener: (src: Readable) -> Unit)
fun on(event: WritableEvent.UNPIPE, listener: (src: Readable) -> Unit)
Link copied to clipboard
open fun once(event: Symbol, listener: Function<Unit>)
open fun once(event: String, listener: Function<Unit>)
fun once(event: WritableEvent.CLOSE, listener: () -> Unit)
fun once(event: WritableEvent.DRAIN, listener: () -> Unit)
fun once(event: WritableEvent.ERROR, listener: (JsError) -> Unit)
fun once(event: WritableEvent.FINISH, listener: () -> Unit)
fun once(event: WritableEvent.PIPE, listener: (src: Readable) -> Unit)
fun once(event: WritableEvent.UNPIPE, listener: (src: Readable) -> Unit)
Link copied to clipboard
fun <T : WritableStream> pipe(destination: T, options: StreamPipeOptions = definedExternally): T
Link copied to clipboard
open fun prependListener(event: Symbol, listener: Function<Unit>)
open fun prependListener(event: String, listener: Function<Unit>)
fun prependListener(event: WritableEvent.CLOSE, listener: () -> Unit)
fun prependListener(event: WritableEvent.DRAIN, listener: () -> Unit)
fun prependListener(event: WritableEvent.ERROR, listener: (JsError) -> Unit)
fun prependListener(event: WritableEvent.FINISH, listener: () -> Unit)
fun prependListener(event: WritableEvent.PIPE, listener: (src: Readable) -> Unit)
fun prependListener(event: WritableEvent.UNPIPE, listener: (src: Readable) -> Unit)
Link copied to clipboard
open fun prependOnceListener(event: Symbol, listener: Function<Unit>)
open fun prependOnceListener(event: String, listener: Function<Unit>)
fun prependOnceListener(event: WritableEvent.CLOSE, listener: () -> Unit)
fun prependOnceListener(event: WritableEvent.DRAIN, listener: () -> Unit)
fun prependOnceListener(event: WritableEvent.FINISH, listener: () -> Unit)
fun prependOnceListener(event: WritableEvent.PIPE, listener: (src: Readable) -> Unit)
fun prependOnceListener(event: WritableEvent.UNPIPE, listener: (src: Readable) -> Unit)
Link copied to clipboard
fun removeHeader(name: String)

Removes a header that is queued for implicit sending.

Link copied to clipboard
open fun removeListener(event: Symbol, listener: Function<Unit>)
open fun removeListener(event: String, listener: Function<Unit>)
fun removeListener(event: WritableEvent.CLOSE, listener: () -> Unit)
fun removeListener(event: WritableEvent.DRAIN, listener: () -> Unit)
fun removeListener(event: WritableEvent.ERROR, listener: (JsError) -> Unit)
fun removeListener(event: WritableEvent.FINISH, listener: () -> Unit)
fun removeListener(event: WritableEvent.PIPE, listener: (src: Readable) -> Unit)
fun removeListener(event: WritableEvent.UNPIPE, listener: (src: Readable) -> 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: ReadonlyArray<String>)
fun setHeader(name: String, value: Double)
fun setHeader(name: String, value: String)

Sets a single header value. If the header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings 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
open fun setTimeout(msecs: Number, callback: () -> Unit = definedExternally)

Once a socket is associated with the message and is connected, socket.setTimeout() will be called with msecs as the first parameter.

Link copied to clipboard
open fun uncork()

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

Link copied to clipboard
open override fun write(buffer: Uint8Array, cb: (JsError?) -> Unit): Boolean
open override fun write(buffer: String, cb: (JsError?) -> Unit): Boolean
open fun write(chunk: Any?, encoding: BufferEncoding, callback: (JsError?) -> Unit = definedExternally): Boolean
open override fun write(str: String, encoding: BufferEncoding, cb: (JsError?) -> Unit): Boolean

open fun write(chunk: Any?, callback: (JsError?) -> Unit = definedExternally): Boolean

The writable.write() method writes some data to the stream, and calls the supplied callback once the data has been fully handled. If an error occurs, the callback will be called with the error as its first argument. The callback is called asynchronously and before 'error' is emitted.

Link copied to clipboard
fun writeContinue(callback: () -> Unit = definedExternally)

Sends an HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent. See the 'checkContinue' event on Server.

Link copied to clipboard
fun writeEarlyHints(hints: ReadonlyRecord<String, Any>, callback: () -> Unit = definedExternally)

Sends an HTTP/1.1 103 Early Hints message 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. The optional callback argument will be called when the response message has been written.

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

fun writeHead(statusCode: Number, statusMessage: String = definedExternally, headers: ReadonlyArray<OutgoingHttpHeader> = definedExternally)
fun writeHead(statusCode: Number, statusMessage: String = definedExternally, 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. Optionally one can give a human-readable statusMessage as the second argument.

Link copied to clipboard

Sends a HTTP/1.1 102 Processing message to the client, indicating that the request body should be sent.