IncomingMessage

open external class IncomingMessage : Readable(source)

An IncomingMessage object is created by {@link Server} or {@link ClientRequest} and passed as the first argument to the 'request' and 'response' event respectively. It may be used to access response status, headers, and data.

Different from its socket value which is a subclass of stream.Duplex, the IncomingMessage itself extends stream.Readable and is created separately to parse and emit the incoming HTTP headers and payload, as the underlying socket may be reused multiple times in case of keep-alive.

Since

v0.1.17

Constructors

Link copied to clipboard
constructor(socket: Socket)

Properties

Link copied to clipboard
open val _construct: (callback: (JsError?) -> Unit) -> Unit?
Link copied to clipboard

The message.aborted property will be true if the request has been aborted.

Link copied to clipboard
open val closed: Boolean

Is true after 'close' has been emitted.

Link copied to clipboard

The message.complete property will be true if a complete HTTP message has been received and successfully parsed.

Link copied to clipboard

Alias for message.socket.

Link copied to clipboard
open var destroyed: Boolean

Is true after readable.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

The request/response headers object.

Link copied to clipboard

Similar to message.headers, but there is no join logic and the values are always arrays of strings, even for headers received just once.

Link copied to clipboard

In case of server request, the HTTP version sent by the client. In the case of client response, the HTTP version of the connected-to server. Probably either '1.1' or '1.0'.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Only valid for request obtained from {@link Server}.

Link copied to clipboard

The raw request/response headers list exactly as they were received.

Link copied to clipboard

The raw request/response trailer keys and values exactly as they were received. Only populated at the 'end' event.

Link copied to clipboard
open override var readable: Boolean

Is true if it is safe to call {@link read}, which means the stream has not been destroyed or emitted 'error' or 'end'.

Link copied to clipboard

Returns whether the stream was destroyed or errored before emitting 'end'.

Link copied to clipboard

Returns whether 'data' has been emitted.

Link copied to clipboard

Getter for the property encoding of a given Readable stream. The encoding property can be set using the {@link setEncoding} method.

Link copied to clipboard

Becomes true when 'end' event is emitted.

Link copied to clipboard

This property reflects the current state of a Readable stream as described in the Three states section.

Link copied to clipboard

Returns the value of highWaterMark passed when creating this Readable.

Link copied to clipboard

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

Link copied to clipboard

Getter for the property objectMode of a given Readable stream.

Link copied to clipboard

The net.Socket object associated with the connection.

Link copied to clipboard

Only valid for response obtained from {@link ClientRequest}.

Link copied to clipboard

Only valid for response obtained from {@link ClientRequest}.

Link copied to clipboard

The request/response trailers object. Only populated at the 'end' event.

Link copied to clipboard

Similar to message.trailers, but there is no join logic and the values are always arrays of strings, even for headers received just once. Only populated at the 'end' event.

Link copied to clipboard
var url: String?

Only valid for request obtained from {@link Server}.

Functions

Link copied to clipboard
open fun _destroy(error: JsError?, callback: (JsError?) -> Unit)
Link copied to clipboard
fun _read(size: Number)
Link copied to clipboard
open fun addListener(event: Symbol, listener: Function<Unit>)
open fun addListener(event: String, listener: Function<Unit>)
fun addListener(event: ReadableEvent.DATA, listener: (chunk: Any?) -> Unit)
fun addListener(event: ReadableEvent.END, listener: () -> Unit)
fun addListener(event: ReadableEvent.ERROR, listener: (JsError) -> Unit)
fun addListener(event: ReadableEvent.PAUSE, listener: () -> Unit)
fun addListener(event: ReadableEvent.READABLE, listener: () -> Unit)
fun addListener(event: ReadableEvent.RESUME, listener: () -> Unit)

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

Event emitter The defined events on documents including:

Link copied to clipboard
fun asIndexedPairs(options: ArrayOptions = definedExternally): Readable

This method returns a new stream with chunks of the underlying stream paired with a counter in the form [index, chunk]. The first index value is 0 and it increases by 1 for each chunk produced.

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 override fun destroy(error: JsError)

Calls destroy() on the socket that received the IncomingMessage. If error is provided, an 'error' event is emitted on the socket and error is passed as an argument to any listeners on the event.

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 readable stream will release any internal resources and subsequent calls to push() will be ignored.

Link copied to clipboard
fun drop(limit: Number, options: ArrayOptions = definedExternally): Readable

This method returns a new stream with the first limit chunks dropped from the start.

Link copied to clipboard
open fun emit(event: Symbol, vararg args: Any?): Boolean
open fun emit(event: String, vararg args: Any?): Boolean
fun emit(event: ReadableEvent.DATA, chunk: Any?): Boolean
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 every(fn: (data: Any?, options: ArrayOptions?) -> PromiseResult<Boolean>, options: ArrayOptions = definedExternally): Promise<Boolean>

This method is similar to Array.prototype.every and calls fn on each chunk in the stream to check if all awaited return values are truthy value for fn. Once an fn call on a chunk awaited return value is falsy, the stream is destroyed and the promise is fulfilled with false. If all of the fn calls on the chunks return a truthy value, the promise is fulfilled with true.

Link copied to clipboard
fun filter(fn: (data: Any?, options: ArrayOptions?) -> PromiseResult<Boolean>, options: ArrayOptions = definedExternally): Readable

This method allows filtering the stream. For each chunk in the stream the fn function will be called and if it returns a truthy value, the chunk will be passed to the result stream. If the fn function returns a promise - that promise will be awaited.

Link copied to clipboard
fun find(fn: (data: Any?, options: ArrayOptions?) -> PromiseResult<Boolean>, options: ArrayOptions = definedExternally): Promise<Any?>

fun <T> find(fn: (data: Any?, options: ArrayOptions?) -> Boolean, options: ArrayOptions = definedExternally): Promise<T?>

This method is similar to Array.prototype.find and calls fn on each chunk in the stream to find a chunk with a truthy value for fn. Once an fn call's awaited return value is truthy, the stream is destroyed and the promise is fulfilled with value for which fn returned a truthy value. If all of the fn calls on the chunks return a falsy value, the promise is fulfilled with undefined.

Link copied to clipboard
fun flatMap(fn: (data: Any?, options: ArrayOptions?) -> Any?, options: ArrayOptions = definedExternally): Readable

This method returns a new stream by applying the given callback to each chunk of the stream and then flattening the result.

Link copied to clipboard
fun forEach(fn: (data: Any?, options: ArrayOptions?) -> PromiseResult<Void>, options: ArrayOptions = definedExternally): Promise<Void>

This method allows iterating a stream. For each chunk in the stream the fn function will be called. If the fn function returns a promise - that promise will be awaited.

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
open override fun isPaused(): Boolean

The readable.isPaused() method returns the current operating state of the Readable. This is used primarily by the mechanism that underlies the readable.pipe() method. In most typical cases, there will be no reason to use this method directly.

Link copied to clipboard
fun iterator(options: ReadableBaseIteratorOptions = definedExternally): AsyncIterator<Any?>

The iterator created by this method gives users the option to cancel the destruction of the stream if the for await...of loop is exited by return, break, or throw, or if the iterator should destroy the stream if the stream emitted an error during iteration.

Link copied to clipboard
fun map(fn: (data: Any?, options: ArrayOptions?) -> Any?, options: ArrayOptions = definedExternally): Readable

This method allows mapping over the stream. The fn function will be called for every chunk in the stream. If the fn function returns a promise - that promise will be awaited before being passed to the result stream.

Link copied to clipboard
open fun on(event: Symbol, listener: Function<Unit>)
open fun on(event: String, listener: Function<Unit>)
fun on(event: ReadableEvent.CLOSE, listener: () -> Unit)
fun on(event: ReadableEvent.DATA, listener: (chunk: Any?) -> Unit)
fun on(event: ReadableEvent.END, listener: () -> Unit)
fun on(event: ReadableEvent.ERROR, listener: (JsError) -> Unit)
fun on(event: ReadableEvent.PAUSE, listener: () -> Unit)
fun on(event: ReadableEvent.READABLE, listener: () -> Unit)
fun on(event: ReadableEvent.RESUME, listener: () -> Unit)
Link copied to clipboard
open fun once(event: Symbol, listener: Function<Unit>)
open fun once(event: String, listener: Function<Unit>)
fun once(event: ReadableEvent.CLOSE, listener: () -> Unit)
fun once(event: ReadableEvent.DATA, listener: (chunk: Any?) -> Unit)
fun once(event: ReadableEvent.END, listener: () -> Unit)
fun once(event: ReadableEvent.ERROR, listener: (JsError) -> Unit)
fun once(event: ReadableEvent.PAUSE, listener: () -> Unit)
fun once(event: ReadableEvent.READABLE, listener: () -> Unit)
fun once(event: ReadableEvent.RESUME, listener: () -> Unit)
Link copied to clipboard
open override fun pause()

The readable.pause() method will cause a stream in flowing mode to stop emitting 'data' events, switching out of flowing mode. Any data that becomes available will remain in the internal buffer.

Link copied to clipboard
open override fun <T : WritableStream> pipe(destination: T, options: ReadableStreamPipeOptions): T
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: ReadableEvent.CLOSE, listener: () -> Unit)
fun prependListener(event: ReadableEvent.DATA, listener: (chunk: Any?) -> Unit)
fun prependListener(event: ReadableEvent.END, listener: () -> Unit)
fun prependListener(event: ReadableEvent.ERROR, listener: (JsError) -> Unit)
fun prependListener(event: ReadableEvent.PAUSE, listener: () -> Unit)
fun prependListener(event: ReadableEvent.READABLE, listener: () -> Unit)
fun prependListener(event: ReadableEvent.RESUME, listener: () -> Unit)
Link copied to clipboard
open fun prependOnceListener(event: Symbol, listener: Function<Unit>)
open fun prependOnceListener(event: String, listener: Function<Unit>)
fun prependOnceListener(event: ReadableEvent.CLOSE, listener: () -> Unit)
fun prependOnceListener(event: ReadableEvent.DATA, listener: (chunk: Any?) -> Unit)
fun prependOnceListener(event: ReadableEvent.END, listener: () -> Unit)
fun prependOnceListener(event: ReadableEvent.PAUSE, listener: () -> Unit)
fun prependOnceListener(event: ReadableEvent.READABLE, listener: () -> Unit)
fun prependOnceListener(event: ReadableEvent.RESUME, listener: () -> Unit)
Link copied to clipboard
fun push(chunk: Any?, encoding: BufferEncoding = definedExternally): Boolean
Link copied to clipboard
open override fun read(size: Number): Any

Calls readable.destroy() with an AbortError and returns a promise that fulfills when the stream is finished.

Link copied to clipboard
open fun readOrNull(size: Number = definedExternally): Any?

The readable.read() method reads data out of the internal buffer and returns it. If no data is available to be read, null is returned. By default, the data is returned as a Buffer object unless an encoding has been specified using the readable.setEncoding() method or the stream is operating in object mode.

Link copied to clipboard
fun <T> reduce(fn: (previous: T, data: Any?, options: ArrayOptions?) -> T, initial: T, options: ArrayOptions = definedExternally): Promise<T>

fun <T> reduce(fn: (previous: Any?, data: Any?, options: ArrayOptions?) -> T, initial: Nothing? = definedExternally, options: ArrayOptions = definedExternally): Promise<T>

This method calls fn on each chunk of the stream in order, passing it the result from the calculation on the previous element. It returns a promise for the final value of the reduction.

Link copied to clipboard
open fun removeListener(event: Symbol, listener: Function<Unit>)
open fun removeListener(event: String, listener: Function<Unit>)
fun removeListener(event: ReadableEvent.CLOSE, listener: () -> Unit)
fun removeListener(event: ReadableEvent.DATA, listener: (chunk: Any?) -> Unit)
fun removeListener(event: ReadableEvent.END, listener: () -> Unit)
fun removeListener(event: ReadableEvent.ERROR, listener: (JsError) -> Unit)
fun removeListener(event: ReadableEvent.PAUSE, listener: () -> Unit)
fun removeListener(event: ReadableEvent.READABLE, listener: () -> Unit)
fun removeListener(event: ReadableEvent.RESUME, listener: () -> Unit)
Link copied to clipboard
open override fun resume()

The readable.resume() method causes an explicitly paused Readable stream to resume emitting 'data' events, switching the stream into flowing mode.

Link copied to clipboard
open override fun setEncoding(encoding: BufferEncoding)

The readable.setEncoding() method sets the character encoding for data read from the Readable stream.

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)

Calls message.socket.setTimeout(msecs, callback).

Link copied to clipboard
fun some(fn: (data: Any?, options: ArrayOptions?) -> PromiseResult<Boolean>, options: ArrayOptions = definedExternally): Promise<Boolean>

This method is similar to Array.prototype.some and calls fn on each chunk in the stream until the awaited return value is true (or any truthy value). Once an fn call on a chunk awaited return value is truthy, the stream is destroyed and the promise is fulfilled with true. If none of the fn calls on the chunks return a truthy value, the promise is fulfilled with false.

Link copied to clipboard
fun take(limit: Number, options: ArrayOptions = definedExternally): Readable

This method returns a new stream with the first limit chunks.

Link copied to clipboard
fun toArray(options: ArrayOptions = definedExternally): Promise<ReadonlyArray<Any?>>

This method allows easily obtaining the contents of a stream.

Link copied to clipboard
open override fun unpipe(destination: WritableStream)

The readable.unpipe() method detaches a Writable stream previously attached using the {@link pipe} method.

Link copied to clipboard
open override fun unshift(chunk: Uint8Array, encoding: BufferEncoding)
open override fun unshift(chunk: String, encoding: BufferEncoding)

fun unshift(chunk: Any?, encoding: BufferEncoding = definedExternally)

Passing chunk as null signals the end of the stream (EOF) and behaves the same as readable.push(null), after which no more data can be written. The EOF signal is put at the end of the buffer and any buffered data will still be flushed.

Link copied to clipboard
open override fun wrap(stream: ReadableStream)

Prior to Node.js 0.10, streams did not implement the entire node:stream module API as it is currently defined. (See Compatibility for more information.)