超时选项¶
It is a good practice to set a timeout to prevent hanging requests.
By default, there is no timeout set.
All numbers refer to milliseconds.
timeout
¶
类型: object
This object describes the maximum allowed time for particular events.
lookup
¶
类型: number
Starts when a socket is assigned.
Ends when the hostname has been resolved.
Does not apply when using a Unix domain socket.
Does not apply when passing an IP address.
It is preferred to not use any greater value than 100
.
connect
¶
类型: number
Starts when lookup completes.
Ends when the socket is fully connected.
If lookup
does not apply to the request, this event starts when the socket is assigned and ends when the socket is connected.
secureConnect
¶
类型: number
Starts when connect
completes.
Ends when the handshake process completes.
This timeout applies only to HTTPS requests.
socket
¶
类型: number
Starts when the socket is connected.
Resets when new data is transferred.
It is the same as request.setTimeout(timeout)
which calls socket.setTimeout(timeout)
after a socket is assigned to this request and is connected.
send
¶
类型: number
Starts when the socket is connected.
Ends when all data have been written to the socket.
Note:
- This does not assure the data have been received by the other end!
- It only assures that the data have been passed to the underlying OS.
response
¶
类型: number
Starts when request has been flushed.
Ends when the headers are received.
read
¶
read
类型: number
Starts when the headers are received.
Ends when the response's end
event fires.
Note:
- This timeout is blocked by https://github.com/nodejs/node/issues/35923
request
¶
类型: number
Starts when the request is initiated.
Ends when the response's end
event fires.
In other words, this is the global timeout.