class IncomingMessage extends Object with StObject
An IncomingMessage
object is created by Server
or 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
, theIncomingMessage
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.
- Annotations
- @JSType() @JSImport("http", "IncomingMessage") @native()
- Since
v0.1.17
- Alphabetic
- By Inheritance
- IncomingMessage
- StObject
- Object
- Any
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- var aborted: Boolean
The
message.aborted
property will betrue
if the request has been aborted.The
message.aborted
property will betrue
if the request has been aborted.- Since
v10.1.0
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- var complete: Boolean
The
message.complete
property will betrue
if a complete HTTP message has been received and successfully parsed.The
message.complete
property will betrue
if a complete HTTP message has been received and successfully parsed.This property is particularly useful as a means of determining if a client or server fully transmitted a message before a connection was terminated:
js const req = http.request({ host: '127.0.0.1', port: 8080, method: 'POST' }, (res) => { res.resume(); res.on('end', () => { if (!res.complete) console.error( 'The connection was terminated while the message was still being sent'); }); });
- Since
v0.3.0
- def destroy(error: Error): Unit
- def destroy(): Unit
Calls
destroy()
on the socket that received theIncomingMessage
.Calls
destroy()
on the socket that received theIncomingMessage
. Iferror
is provided, an'error'
event is emitted on the socket anderror
is passed as an argument to any listeners on the event.- Since
v0.3.0
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hasOwnProperty(v: String): Boolean
- Definition Classes
- Object
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- var headers: IncomingHttpHeaders
The request/response headers object.
The request/response headers object.
Key-value pairs of header names and values. Header names are lower-cased.
js // Prints something like: // // { 'user-agent': 'curl/7.22.0', // host: '127.0.0.1:8000', // accept: '*' } console.log(request.headers);
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
,server
, oruser-agent
are discarded. *set-cookie
is always an array. Duplicates are added to the array. * For duplicatecookie
headers, the values are joined together with '; '. * For all other headers, the values are joined together with ', '.- Since
v0.1.5
- var httpVersion: String
In case of server request, the HTTP version sent by the client.
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'
.Also
message.httpVersionMajor
is the first integer andmessage.httpVersionMinor
is the second.- Since
v0.1.1
- var httpVersionMajor: Double
- var httpVersionMinor: Double
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isPrototypeOf(v: Object): Boolean
- Definition Classes
- Object
- var method: UndefOr[String]
**Only valid for request obtained from
Server
.****Only valid for request obtained from
Server
.**The request method as a string. Read only. Examples:
'GET'
,'DELETE'
.- Since
v0.1.1
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def propertyIsEnumerable(v: String): Boolean
- Definition Classes
- Object
- var rawHeaders: Array[String]
The raw request/response headers list exactly as they were received.
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.
js // Prints something like: // // [ 'user-agent', // 'this is invalid because there can be only one', // 'User-Agent', // 'curl/7.22.0', // 'Host', // '127.0.0.1:8000', // 'ACCEPT', // '*' ] console.log(request.rawHeaders);
- Since
v0.11.6
- var rawTrailers: Array[String]
The raw request/response trailer keys and values exactly as they were received.
The raw request/response trailer keys and values exactly as they were received. Only populated at the
'end'
event.- Since
v0.11.6
- def setTimeout(msecs: Double, callback: Function0[Unit]): IncomingMessage.this.type
- def setTimeout(msecs: Double): IncomingMessage.this.type
Calls
message.socket.setTimeout(msecs, callback)
.Calls
message.socket.setTimeout(msecs, callback)
.- Since
v0.5.9
- var socket: Socket
The
net.Socket
object associated with the connection.The
net.Socket
object associated with the connection.With HTTPS support, use
request.socket.getPeerCertificate()
to obtain the client's authentication details.This property is guaranteed to be an instance of the
net.Socket
class, a subclass ofstream.Duplex
, unless the user specified a socket type other thannet.Socket
.- Since
v0.3.0
- var statusCode: UndefOr[Double]
**Only valid for response obtained from
ClientRequest
.****Only valid for response obtained from
ClientRequest
.**The 3-digit HTTP response status code. E.G.
404
.- Since
v0.1.1
- var statusMessage: UndefOr[String]
**Only valid for response obtained from
ClientRequest
.****Only valid for response obtained from
ClientRequest
.**The HTTP response status message (reason phrase). E.G.
OK
orInternal Server Error
.- Since
v0.11.10
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toLocaleString(): String
- Definition Classes
- Object
- def toString(): String
- Definition Classes
- AnyRef → Any
- var trailers: Dict[String]
The request/response trailers object.
The request/response trailers object. Only populated at the
'end'
event.- Since
v0.3.0
- var url: UndefOr[String]
**Only valid for request obtained from
Server
.****Only valid for request obtained from
Server
.**Request URL string. This contains only the URL that is present in the actual HTTP request. Take the following request:
http GET /status?name=ryan HTTP/1.1 Accept: text/plain
To parse the URL into its parts:
);js new URL(request.url,
http://${request.headers.host}When
request.url
is'/status?name=ryan'
andrequest.headers.host
is'localhost:3000'
:
) URL { href: 'http://localhost:3000/status?name=ryan', origin: 'http://localhost:3000', protocol: 'http:', username: , password: , host: 'localhost:3000', hostname: 'localhost', port: '3000', pathname: '/status', search: '?name=ryan', searchParams: URLSearchParams { 'name' => 'ryan' }, hash: }console $ node > new URL(request.url,
http://${request.headers.host}- Since
v0.1.90
- def valueOf(): Any
- Definition Classes
- Object
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])