object httpMod
- Alphabetic
- By Inheritance
- httpMod
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Type Members
- class Agent extends Object with StObject
An
Agent
is responsible for managing connection persistence and reuse for HTTP clients.An
Agent
is responsible for managing connection persistence and reuse for HTTP clients. It maintains a queue of pending requests for a given host and port, reusing a single socket connection for each until the queue is empty, at which time the socket is either destroyed or put into a pool where it is kept to be used again for requests to the same host and port. Whether it is destroyed or pooled depends on thekeepAlive
option
.Pooled connections have TCP Keep-Alive enabled for them, but servers may still close idle connections, in which case they will be removed from the pool and a new connection will be made when a new HTTP request is made for that host and port. Servers may also refuse to allow multiple requests over the same connection, in which case the connection will have to be remade for every request and cannot be pooled. The
Agent
will still make the requests to that server, but each one will occur over a new connection.When a connection is closed by the client or the server, it is removed from the pool. Any unused sockets in the pool will be unrefed so as not to keep the Node.js process running when there are no outstanding requests. (see
socket.unref()
).It is good practice, to
destroy()
anAgent
instance when it is no longer in use, because unused sockets consume OS resources.Sockets are removed from an agent when the socket emits either a
'close'
event or an'agentRemove'
event. When intending to keep one HTTP request open for a long time without keeping it in the agent, something like the following may be done:js http.get(options, (res) => { // Do stuff }).on('socket', (socket) => { socket.emit('agentRemove'); });
An agent may also be used for an individual request. By providing
{agent: false}
as an option to thehttp.get()
orhttp.request()
functions, a one-time useAgent
with default options will be used for the client connection.agent:false
:js http.get({ hostname: 'localhost', port: 80, path: '/', agent: false // Create a new agent just for this one request }, (res) => { // Do stuff with response });
- Annotations
- @JSType() @JSImport("http", "Agent") @native()
- Since
v0.3.4
- trait AgentOptions extends Object with StObject
- Annotations
- @JSType() @native()
- class ClientRequest extends Object with StObject
This object is created internally and returned from
request
.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 thesetHeader(name, value)
,getHeader(name)
,removeHeader(name)
API. The actual header will be sent along with the first data chunk or when callingrequest.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 ofIncomingMessage
.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 callingresponse.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
- trait ClientRequestArgs extends Object with StObject
- Annotations
- @JSType() @native()
- trait IncomingHttpHeaders extends Object with StObject with Dict[|[String, Array[String]]]
- Annotations
- @JSType() @native()
- class IncomingMessage extends Object with StObject
An
IncomingMessage
object is created byServer
orClientRequest
and passed as the first argument to the'request'
and'response'
event respectively.An
IncomingMessage
object is created byServer
orClientRequest
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 ofstream.Duplex
, theIncomingMessage
itself extendsstream.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
- trait InformationEvent extends Object with StObject
- Annotations
- @JSType() @native()
- type OutgoingHttpHeader = |[|[Double, String], Array[String]]
- type OutgoingHttpHeaders = StringDictionary[UndefOr[OutgoingHttpHeader]]
- type RequestListener = Function2[IncomingMessage, ServerResponse, Unit]
- class Server extends Object with StObject
- Annotations
- @JSType() @JSImport("http", "Server") @native()
- Since
v0.1.17
- trait ServerOptions extends Object with StObject
- Annotations
- @JSType() @native()
- class ServerResponse extends Object with StObject
This object is created internally by an HTTP server, not by the user.
This object is created internally by an HTTP server, not by the user. It is passed as the second parameter to the
'request'
event.- Annotations
- @JSType() @JSImport("http", "ServerResponse") @native()
- Since
v0.1.17
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
- 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 hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- 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()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- 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])
- object AgentOptions
- object ClientRequestArgs
- object IncomingHttpHeaders
- object InformationEvent
- object ServerOptions
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated