An IncomingMessage object is created by http.Server or http.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.

It implements the Readable Stream interface, as well as the following additional events, methods, and properties.

Variables

read onlyaborted:Bool

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

read onlycomplete:Bool

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

read onlyconnection:Socket

Alias for socket.

read onlyheaders:DynamicAccess<EitherType<String, Array<String>>>

The request/response headers object.

Key-value pairs of header names and values. Header names are lower-cased.

Duplicates in raw headers are handled in the following ways, depending on the header name:

  • Duplicates of age, authorization, content-length, content-type, etag, expires, from, host, if-modified-since, if-unmodified-since, last-modified, location, max-forwards, proxy-authorization, referer, retry-after, or user-agent are discarded.
  • set-cookie is always an array. Duplicates are added to the array.
  • For duplicate cookie headers, the values are joined together with '; '.
  • For all other headers, the values are joined together with ', '.

read onlyhttpVersion:String

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'.

read onlyhttpVersionMajor:Int

HTTP Version first integer

read onlyhttpVersionMinor:Int

HTTP Version second integer

read onlymethod:Method

Only valid for request obtained from* Server.

The request method as a string. Read only. Example: 'GET', 'DELETE'.

read onlyrawHeaders:Array<String>

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

The keys and values are in the same list. It is not a list of tuples. So, the even-numbered offsets are key values, and the odd-numbered offsets are the associated values.

Header names are not lowercased, and duplicates are not merged.

read onlyrawTrailers:Array<String>

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

read onlysocket:Socket

The Socket object associated with the connection.

With HTTPS support, use request.socket.getPeerCertificate() to obtain the client's authentication details.

read onlystatusCode:Int

Only valid for response obtained from* ClientRequest. The 3-digit HTTP response status code. E.G. 404.

read onlystatusMessage:String

Only valid for response obtained from* ClientRequest. The HTTP response status message (reason phrase). E.G. OK or Internal Server Error.

read onlytrailers:DynamicAccess<String>

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

read onlyurl:String

Only valid for request obtained from* Server.

Request URL string. This contains only the URL that is present in the actual HTTP request.

Methods

destroy(?error:Error):IncomingMessage

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

setTimeout(msecs:Int, ?callback:() ‑> Void):Void

Calls connection.setTimeout(msecs, callback).

Inherited Variables

Defined by Readable

read onlydestroyed:Bool

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

See also:

read onlyisTTY:Bool

Terminal read streams (i.e. process.stdin) have this property set to true. It is false for any other read streams.

See also:

read onlyreadable:Bool

Is true if it is safe to call readable.read().

See also:

read onlyreadableEncoding:Null<String>

Getter for the property encoding of a given Readable stream. The encoding property can be set using the readable.setEncoding() method.

See also:

read onlyreadableHighWaterMark:Int

Returns the value of highWaterMark passed when constructing this Readable.

See also:

read onlyreadableLength:Int

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.

See also:

read onlyreadableObjectMode:Bool

Getter for the property objectMode of a given Readable stream.

See also:

Inherited Methods

Defined by Readable

isPaused():Bool

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.

See also:

pause():TSelf

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.

See also:

pipe<T>(destination:T, ?options:{end:Null<Bool>}):T

The readable.pipe() method attaches a Writable stream to the readable, causing it to switch automatically into flowing mode and push all of its data to the attached Writable. The flow of data will be automatically managed so that the destination Writable stream is not overwhelmed by a faster Readable stream.

See also:

read(?size:Int):Null<Dynamic>

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

See also:

resume():TSelf

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

See also:

setEncoding(encoding:String):TSelf

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

See also:

unpipe(?destination:IWritable):TSelf

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

See also:

unshift(chunk:Null<Dynamic>, ?encoding:String):Void

Passing chunk as null signals the end of the stream (EOF), after which no more data can be written.

See also:

wrap(stream:Dynamic):IReadable

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

See also:

Defined by EventEmitter

addListener<T>(eventName:Event<T>, listener:T):TSelf

emit<T>(eventName:Event<T>, args:Rest<Dynamic>):Bool

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

See also:

eventNames():Array<EitherType<String, Symbol>>

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

See also:

getMaxListeners():Int

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

See also:

listenerCount<T>(eventName:Event<T>):Int

Returns the number of listeners listening to the event named eventName.

See also:

listeners<T>(eventName:Event<T>):Array<T>

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

See also:

off<T>(eventName:Event<T>, listener:T):TSelf

on<T>(eventName:Event<T>, listener:T):TSelf

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.

See also:

once<T>(eventName:Event<T>, listener:T):TSelf

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

See also:

prependListener<T>(eventName:Event<T>, listener:T):TSelf

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.

See also:

prependOnceListener<T>(eventName:Event<T>, listener:T):TSelf

Adds a one-time listener 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.

See also:

rawListeners<T>(eventName:Event<T>):Array<T>

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

See also:

removeAllListeners<T>(?eventName:Event<T>):TSelf

Removes all listeners, or those of the specified eventName.

See also:

removeListener<T>(eventName:Event<T>, listener:T):TSelf

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

See also:

setMaxListeners(n:Int):Void

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. Obviously, not all events should be limited to just 10 listeners. 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.

See also: