Usage in Deno
import { Server } from "node:http";
Server(requestListener?: RequestListener<Request, Response>)
Server(options: ServerOptions<Request, Response>,requestListener?: RequestListener<Request, Response>,)
Request extends IncomingMessage = IncomingMessage
Response extends ServerResponse = ServerResponse
headersTimeout: number
Limit the amount of time the parser will wait to receive the complete HTTP headers.
If the timeout expires, the server responds with status 408 without forwarding the request to the request listener and then closes the connection.
It must be set to a non-zero value (e.g. 120 seconds) to protect against potential Denial-of-Service attacks in case the server is deployed without a reverse proxy in front.
keepAliveTimeout: number
The number of milliseconds of inactivity a server needs to wait for additional
incoming data, after it has finished writing the last response, before a socket
will be destroyed. If the server receives new data before the keep-alive
timeout has fired, it will reset the regular inactivity timeout, i.e., server.timeout
.
A value of 0
will disable the keep-alive timeout behavior on incoming
connections.
A value of 0
makes the http server behave similarly to Node.js versions prior
to 8.0.0, which did not have a keep-alive timeout.
The socket timeout logic is set up on connection, so changing this value only affects new connections to the server, not any existing connections.
maxHeadersCount: number | null
Limits maximum incoming headers count. If set to 0, no limit will be applied.
maxRequestsPerSocket: number | null
The maximum number of requests socket can handle before closing keep alive connection.
A value of 0
will disable the limit.
When the limit is reached it will set the Connection
header value to close
,
but will not actually close the connection, subsequent requests sent
after the limit is reached will get 503 Service Unavailable
as a response.
requestTimeout: number
Sets the timeout value in milliseconds for receiving the entire request from the client.
If the timeout expires, the server responds with status 408 without forwarding the request to the request listener and then closes the connection.
It must be set to a non-zero value (e.g. 120 seconds) to protect against potential Denial-of-Service attacks in case the server is deployed without a reverse proxy in front.
timeout: number
The number of milliseconds of inactivity before a socket is presumed to have timed out.
A value of 0
will disable the timeout behavior on incoming connections.
The socket timeout logic is set up on connection, so changing this value only affects new connections to the server, not any existing connections.
addListener(event: string,listener: (...args: any[]) => void,): this
addListener(event: "close",listener: () => void,): this
addListener(event: "connection",listener: (socket: Socket) => void,): this
addListener(event: "error",listener: (err: Error) => void,): this
addListener(event: "listening",listener: () => void,): this
addListener(event: "checkContinue",listener: RequestListener<Request, Response>,): this
addListener(event: "checkExpectation",listener: RequestListener<Request, Response>,): this
addListener(event: "clientError",listener: (err: Error,socket: stream.Duplex,) => void,): this
addListener(event: "connect",listener: () => void,): this
addListener(event: "dropRequest",listener: (req: InstanceType<Request>,socket: stream.Duplex,) => void,): this
addListener(event: "request",listener: RequestListener<Request, Response>,): this
addListener(event: "upgrade",listener: () => void,): this
closeAllConnections(): void
Closes all connections connected to this server.
closeIdleConnections(): void
Closes all connections connected to this server which are not sending a request or waiting for a response.
emit(event: string,...args: any[],): boolean
emit(event: "close"): boolean
emit(event: "error",err: Error,): boolean
emit(event: "listening"): boolean
emit(event: "clientError",err: Error,socket: stream.Duplex,): boolean
on(event: string,listener: (...args: any[]) => void,): this
on(event: "close",listener: () => void,): this
on(event: "error",listener: (err: Error) => void,): this
on(event: "listening",listener: () => void,): this
on(event: "checkContinue",listener: RequestListener<Request, Response>,): this
on(event: "checkExpectation",listener: RequestListener<Request, Response>,): this
on(event: "clientError",listener: (err: Error,socket: stream.Duplex,) => void,): this
on(event: "request",listener: RequestListener<Request, Response>,): this
once(event: string,listener: (...args: any[]) => void,): this
once(event: "close",listener: () => void,): this
once(event: "error",listener: (err: Error) => void,): this
once(event: "listening",listener: () => void,): this
once(event: "checkContinue",listener: RequestListener<Request, Response>,): this
once(event: "checkExpectation",listener: RequestListener<Request, Response>,): this
once(event: "clientError",listener: (err: Error,socket: stream.Duplex,) => void,): this
once(event: "request",listener: RequestListener<Request, Response>,): this
prependListener(event: string,listener: (...args: any[]) => void,): this
prependListener(event: "close",listener: () => void,): this
prependListener(event: "connection",listener: (socket: Socket) => void,): this
prependListener(event: "error",listener: (err: Error) => void,): this
prependListener(event: "listening",listener: () => void,): this
prependListener(event: "checkContinue",listener: RequestListener<Request, Response>,): this
prependListener(event: "checkExpectation",listener: RequestListener<Request, Response>,): this
prependListener(event: "clientError",listener: (err: Error,socket: stream.Duplex,) => void,): this
prependListener(event: "connect",listener: () => void,): this
prependListener(event: "dropRequest",listener: (req: InstanceType<Request>,socket: stream.Duplex,) => void,): this
prependListener(event: "request",listener: RequestListener<Request, Response>,): this
prependListener(event: "upgrade",listener: () => void,): this
prependOnceListener(event: string,listener: (...args: any[]) => void,): this
prependOnceListener(event: "close",listener: () => void,): this
prependOnceListener(event: "connection",listener: (socket: Socket) => void,): this
prependOnceListener(event: "error",listener: (err: Error) => void,): this
prependOnceListener(event: "listening",listener: () => void,): this
prependOnceListener(event: "checkContinue",listener: RequestListener<Request, Response>,): this
prependOnceListener(event: "checkExpectation",listener: RequestListener<Request, Response>,): this
prependOnceListener(event: "clientError",listener: (err: Error,socket: stream.Duplex,) => void,): this
prependOnceListener(event: "connect",listener: () => void,): this
prependOnceListener(event: "dropRequest",listener: (req: InstanceType<Request>,socket: stream.Duplex,) => void,): this
prependOnceListener(event: "request",listener: RequestListener<Request, Response>,): this
prependOnceListener(event: "upgrade",listener: () => void,): this
setTimeout(msecs?: number,callback?: () => void,): this
Sets the timeout value for sockets, and emits a 'timeout'
event on
the Server object, passing the socket as an argument, if a timeout
occurs.
If there is a 'timeout'
event listener on the Server object, then it
will be called with the timed-out socket as an argument.
By default, the Server does not timeout sockets. However, if a callback
is assigned to the Server's 'timeout'
event, timeouts must be handled
explicitly.
setTimeout(callback: () => void): this