class ClientRequest extends Object with StObject
This object is created internally and returned from request
. It
represents an _in-progress_ request whose header has already been queued. The
header is still mutable using the setHeader(name, value)
,getHeader(name)
, removeHeader(name)
API. The actual header will
be sent along with the first data chunk or when calling request.end()
.
To get the response, add a listener for 'response'
to the request object.'response'
will be emitted from the request object when the response
headers have been received. The 'response'
event is executed with one
argument which is an instance of IncomingMessage
.
During the 'response'
event, one can add listeners to the
response object; particularly to listen for the 'data'
event.
If no 'response'
handler is added, then the response will be
entirely discarded. However, if a 'response'
event handler is added,
then the data from the response object **must** be consumed, either by
calling response.read()
whenever there is a 'readable'
event, or
by adding a 'data'
handler, or by calling the .resume()
method.
Until the data is consumed, the 'end'
event will not fire. Also, until
the data is read it will consume memory that can eventually lead to a
'process out of memory' error.
For backward compatibility, res
will only emit 'error'
if there is an'error'
listener registered.
Node.js does not check whether Content-Length and the length of the body which has been transmitted are equal or not.
- Annotations
- @JSType() @JSImport("http", "ClientRequest") @native()
- Since
v0.1.17
- Alphabetic
- By Inheritance
- ClientRequest
- StObject
- Object
- Any
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new ClientRequest(url: String, cb: Function1[IncomingMessage, Unit])
- new ClientRequest(url: URL, cb: Function1[IncomingMessage, Unit])
- new ClientRequest(url: ClientRequestArgs, cb: Function1[IncomingMessage, Unit])
- new ClientRequest(url: String)
- new ClientRequest(url: URL)
- new ClientRequest(url: ClientRequestArgs)
- new ClientRequest()
- Attributes
- protected
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
request.aborted
property will betrue
if the request has been aborted.The
request.aborted
property will betrue
if the request has been aborted.- Since
v0.11.14
- def addListener(event: Symbol, listener: Function1[Any, Unit]): ClientRequest.this.type
- def addListener(event: String, listener: Function1[Any, Unit]): ClientRequest.this.type
- def addListener_abort(event: abort, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_close(event: close, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_connect(event: connect, listener: Function3[IncomingMessage, Socket, Buffer, Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_continue(event: continue, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_drain(event: drain, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_error(event: error, listener: Function1[Error, Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_finish(event: finish, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_information(event: information, listener: Function1[InformationEvent, Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_pipe(event: pipe, listener: Function1[Readable, Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_response(event: response, listener: Function1[IncomingMessage, Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_socket(event: socket, listener: Function1[Socket, Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_timeout(event: timeout, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_unpipe(event: unpipe, listener: Function1[Readable, Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- def addListener_upgrade(event: upgrade, listener: Function3[IncomingMessage, Socket, Buffer, Unit]): ClientRequest.this.type
- Annotations
- @JSName("addListener")
- 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()
- 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 getRawHeaderNames(): Array[String]
Returns an array containing the unique names of the current outgoing raw headers.
Returns an array containing the unique names of the current outgoing raw headers. Header names are returned with their exact casing being set.
js request.setHeader('Foo', 'bar'); request.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
const headerNames = request.getRawHeaderNames(); // headerNames === ['Foo', 'Set-Cookie']
- Since
v15.13.0
- def hasOwnProperty(v: String): Boolean
- Definition Classes
- Object
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- var host: String
The request host.
The request host.
- Since
v14.5.0, v12.19.0
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isPrototypeOf(v: Object): Boolean
- Definition Classes
- Object
- var method: String
The request method.
The request method.
- Since
v0.1.97
- 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 on(event: Symbol, listener: Function1[Any, Unit]): ClientRequest.this.type
- def on(event: String, listener: Function1[Any, Unit]): ClientRequest.this.type
- def onSocket(socket: Socket): Unit
- def on_abort(event: abort, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_close(event: close, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_connect(event: connect, listener: Function3[IncomingMessage, Socket, Buffer, Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_continue(event: continue, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_drain(event: drain, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_error(event: error, listener: Function1[Error, Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_finish(event: finish, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_information(event: information, listener: Function1[InformationEvent, Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_pipe(event: pipe, listener: Function1[Readable, Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_response(event: response, listener: Function1[IncomingMessage, Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_socket(event: socket, listener: Function1[Socket, Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_timeout(event: timeout, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_unpipe(event: unpipe, listener: Function1[Readable, Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def on_upgrade(event: upgrade, listener: Function3[IncomingMessage, Socket, Buffer, Unit]): ClientRequest.this.type
- Annotations
- @JSName("on")
- def once(event: Symbol, listener: Function1[Any, Unit]): ClientRequest.this.type
- def once(event: String, listener: Function1[Any, Unit]): ClientRequest.this.type
- def once_abort(event: abort, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_close(event: close, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_connect(event: connect, listener: Function3[IncomingMessage, Socket, Buffer, Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_continue(event: continue, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_drain(event: drain, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_error(event: error, listener: Function1[Error, Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_finish(event: finish, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_information(event: information, listener: Function1[InformationEvent, Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_pipe(event: pipe, listener: Function1[Readable, Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_response(event: response, listener: Function1[IncomingMessage, Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_socket(event: socket, listener: Function1[Socket, Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_timeout(event: timeout, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_unpipe(event: unpipe, listener: Function1[Readable, Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- def once_upgrade(event: upgrade, listener: Function3[IncomingMessage, Socket, Buffer, Unit]): ClientRequest.this.type
- Annotations
- @JSName("once")
- var path: String
The request path.
The request path.
- Since
v0.4.0
- def prependListener(event: Symbol, listener: Function1[Any, Unit]): ClientRequest.this.type
- def prependListener(event: String, listener: Function1[Any, Unit]): ClientRequest.this.type
- def prependListener_abort(event: abort, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_close(event: close, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_connect(event: connect, listener: Function3[IncomingMessage, Socket, Buffer, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_continue(event: continue, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_drain(event: drain, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_error(event: error, listener: Function1[Error, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_finish(event: finish, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_information(event: information, listener: Function1[InformationEvent, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_pipe(event: pipe, listener: Function1[Readable, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_response(event: response, listener: Function1[IncomingMessage, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_socket(event: socket, listener: Function1[Socket, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_timeout(event: timeout, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_unpipe(event: unpipe, listener: Function1[Readable, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependListener_upgrade(event: upgrade, listener: Function3[IncomingMessage, Socket, Buffer, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependListener")
- def prependOnceListener(event: Symbol, listener: Function1[Any, Unit]): ClientRequest.this.type
- def prependOnceListener(event: String, listener: Function1[Any, Unit]): ClientRequest.this.type
- def prependOnceListener_abort(event: abort, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_close(event: close, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_connect(event: connect, listener: Function3[IncomingMessage, Socket, Buffer, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_continue(event: continue, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_drain(event: drain, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_error(event: error, listener: Function1[Error, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_finish(event: finish, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_information(event: information, listener: Function1[InformationEvent, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_pipe(event: pipe, listener: Function1[Readable, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_response(event: response, listener: Function1[IncomingMessage, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_socket(event: socket, listener: Function1[Socket, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_timeout(event: timeout, listener: Function0[Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_unpipe(event: unpipe, listener: Function1[Readable, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def prependOnceListener_upgrade(event: upgrade, listener: Function3[IncomingMessage, Socket, Buffer, Unit]): ClientRequest.this.type
- Annotations
- @JSName("prependOnceListener")
- def propertyIsEnumerable(v: String): Boolean
- Definition Classes
- Object
- var protocol: String
The request protocol.
The request protocol.
- Since
v14.5.0, v12.19.0
- def setNoDelay(noDelay: Boolean): Unit
- def setNoDelay(): Unit
Once a socket is assigned to this request and is connected
socket.setNoDelay()
will be called.Once a socket is assigned to this request and is connected
socket.setNoDelay()
will be called.- Since
v0.5.9
- def setSocketKeepAlive(enable: Unit, initialDelay: Double): Unit
- def setSocketKeepAlive(enable: Boolean, initialDelay: Double): Unit
- def setSocketKeepAlive(enable: Boolean): Unit
- def setSocketKeepAlive(): Unit
Once a socket is assigned to this request and is connected
socket.setKeepAlive()
will be called.Once a socket is assigned to this request and is connected
socket.setKeepAlive()
will be called.- Since
v0.5.9
- def setTimeout(timeout: Double, callback: Function0[Unit]): ClientRequest.this.type
- def setTimeout(timeout: Double): ClientRequest.this.type
Once a socket is assigned to this request and is connected
socket.setTimeout()
will be called.Once a socket is assigned to this request and is connected
socket.setTimeout()
will be called.- timeout
Milliseconds before a request times out.
- Since
v0.5.9
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toLocaleString(): String
- Definition Classes
- Object
- def toString(): String
- Definition Classes
- AnyRef → Any
- 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])
Deprecated Value Members
- def abort(): Unit
Marks the request as aborting.
Marks the request as aborting. Calling this will cause remaining data in the response to be dropped and the socket to be destroyed.
- Deprecated
Since v14.1.0,v13.14.0 - Use
destroy
instead.- Since
v0.3.8
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated