Struct ntex::web::HttpServer[][src]

pub struct HttpServer<F, I, S, B> where
    F: Fn() -> I + Send + Clone + 'static,
    I: IntoServiceFactory<S, Request, AppConfig>,
    S: ServiceFactory<Request, AppConfig>,
    S::Error: ResponseError,
    S::InitError: Debug,
    S::Response: Into<Response<B>>,
    B: MessageBody
{ /* fields omitted */ }
Expand description

An HTTP Server.

Create new http server with application factory.

use ntex::web::{self, App, HttpResponse, HttpServer};

#[ntex::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(
        || App::new()
            .service(web::resource("/").to(|| async { HttpResponse::Ok() })))
        .bind("127.0.0.1:59090")?
        .run()
        .await
}

Implementations

Create new http server with application factory

Set number of workers to start.

By default http server uses number of available logical cpu as threads count.

Set the maximum number of pending connections.

This refers to the number of clients that can be waiting to be served. Exceeding this number results in the client getting an error when attempting to connect. It should only affect servers under significant load.

Generally set in the 64-2048 range. Default value is 2048.

This method should be called before bind() method call.

Sets the maximum per-worker number of concurrent connections.

All socket listeners will stop accepting connections when this limit is reached for each worker.

By default max connections is set to a 25k.

Sets the maximum per-worker concurrent connection establish process.

All listeners will stop accepting connections when this limit is reached. It can be used to limit the global SSL CPU usage.

By default max connections is set to a 256.

Set server keep-alive setting.

By default keep alive is set to a 5 seconds.

Set server client timeout in seconds for first request.

Defines a timeout for reading client request header. If a client does not transmit the entire set headers within this time, the request is terminated with the 408 (Request Time-out) error.

To disable timeout set value to 0.

By default client timeout is set to 5 seconds.

Set server connection disconnect timeout in seconds.

Defines a timeout for shutdown connection. If a shutdown procedure does not complete within this time, the request is dropped.

To disable timeout set value to 0.

By default client timeout is set to 5 seconds.

Set server ssl handshake timeout in seconds.

Defines a timeout for connection ssl handshake negotiation. To disable timeout set value to 0.

By default handshake timeout is set to 5 seconds.

Set server host name.

Host name is used by application router as a hostname for url generation. Check ConnectionInfo documentation for more information.

By default host name is set to a “localhost” value.

Stop ntex runtime when server get dropped.

By default “stop runtime” is disabled.

Disable signal handling.

By default signal handling is enabled.

Timeout for graceful workers shutdown.

After receiving a stop signal, workers have this much time to finish serving requests. Workers still alive after the timeout are force dropped.

By default shutdown timeout sets to 30 seconds.

Set memory pool.

Use specified memory pool for memory allocations.

Use listener for accepting incoming connection requests

HttpServer does not change any configuration for TcpListener, it needs to be configured before passing it to listen() method.

Use listener for accepting incoming tls connection requests

This method sets alpn protocols to “h2” and “http/1.1”

Use listener for accepting incoming tls connection requests

This method sets alpn protocols to “h2” and “http/1.1”

The socket address to bind

To bind multiple addresses this method can be called multiple times.

Start listening for incoming tls connections.

This method sets alpn protocols to “h2” and “http/1.1”

Start listening for incoming tls connections.

This method sets alpn protocols to “h2” and “http/1.1”

Start listening for unix domain connections on existing listener.

This method is available with uds feature.

Start listening for incoming unix domain connections.

This method is available with uds feature.

Start listening for incoming connections.

This method starts number of http workers in separate threads. For each address this method starts separate thread which does accept() in a loop.

This methods panics if no socket address can be bound or an ntex system is not yet configured.

use ntex::web::{self, App, HttpResponse, HttpServer};

#[ntex::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(
        || App::new().service(web::resource("/").to(|| async { HttpResponse::Ok() }))
    )
        .bind("127.0.0.1:0")?
        .run()
        .await
}

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more