[−][src]Struct actix_web::HttpServer
An HTTP Server.
Create new http server with application factory.
use actix_web::{web, App, HttpResponse, HttpServer}; #[actix_rt::main] async fn main() -> std::io::Result<()> { HttpServer::new( || App::new() .service(web::resource("/").to(|| HttpResponse::Ok()))) .bind("127.0.0.1:59090")? .run() .await }
Implementations
impl<F, I, S, B> HttpServer<F, I, S, B> where
F: Fn() -> I + Send + Clone + 'static,
I: IntoServiceFactory<S>,
S: ServiceFactory<Config = AppConfig, Request = Request>,
S::Error: Into<Error> + 'static,
S::InitError: Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service>::Future: 'static,
B: MessageBody + 'static,
[src]
F: Fn() -> I + Send + Clone + 'static,
I: IntoServiceFactory<S>,
S: ServiceFactory<Config = AppConfig, Request = Request>,
S::Error: Into<Error> + 'static,
S::InitError: Debug,
S::Response: Into<Response<B>> + 'static,
<S::Service as Service>::Future: 'static,
B: MessageBody + 'static,
pub fn new(factory: F) -> Self
[src]
Create new http server with application factory
pub fn on_connect<CB>(self, f: CB) -> HttpServer<F, I, S, B> where
CB: Fn(&dyn Any, &mut Extensions) + Send + Sync + 'static,
[src]
CB: Fn(&dyn Any, &mut Extensions) + Send + Sync + 'static,
Sets function that will be called once before each connection is handled.
It will receive a &std::any::Any
, which contains underlying connection type and an
Extensions container so that request-local data can be passed to middleware and handlers.
For example:
actix_tls::openssl::SslStream<actix_web::rt::net::TcpStream>
when using openssl.actix_tls::rustls::TlsStream<actix_web::rt::net::TcpStream>
when using rustls.actix_web::rt::net::TcpStream
when no encryption is used.
See on_connect
example for additional details.
pub fn workers(self, num: usize) -> Self
[src]
Set number of workers to start.
By default http server uses number of available logical cpu as threads count.
pub fn backlog(self, backlog: i32) -> Self
[src]
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.
pub fn max_connections(self, num: usize) -> Self
[src]
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.
pub fn max_connection_rate(self, num: usize) -> Self
[src]
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 TLS CPU usage.
By default max connections is set to a 256.
pub fn keep_alive<T: Into<KeepAlive>>(self, val: T) -> Self
[src]
Set server keep-alive setting.
By default keep alive is set to a 5 seconds.
pub fn client_timeout(self, val: u64) -> Self
[src]
Set server client timeout in milliseconds 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 5000 milliseconds.
pub fn client_shutdown(self, val: u64) -> Self
[src]
Set server connection shutdown timeout in milliseconds.
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 5000 milliseconds.
pub fn server_hostname<T: AsRef<str>>(self, val: T) -> Self
[src]
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.
pub fn system_exit(self) -> Self
[src]
Stop actix system.
pub fn disable_signals(self) -> Self
[src]
Disable signal handling
pub fn shutdown_timeout(self, sec: u64) -> Self
[src]
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.
pub fn addrs(&self) -> Vec<SocketAddr>ⓘ
[src]
Get addresses of bound sockets.
pub fn addrs_with_scheme(&self) -> Vec<(SocketAddr, &str)>ⓘ
[src]
Get addresses of bound sockets and the scheme for it.
This is useful when the server is bound from different sources with some sockets listening on http and some listening on https and the user should be presented with an enumeration of which socket requires which protocol.
pub fn listen(self, lst: TcpListener) -> Result<Self>
[src]
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.
pub fn listen_openssl(
self,
lst: TcpListener,
builder: SslAcceptorBuilder
) -> Result<Self>
[src]
self,
lst: TcpListener,
builder: SslAcceptorBuilder
) -> Result<Self>
Use listener for accepting incoming tls connection requests
This method sets alpn protocols to "h2" and "http/1.1"
pub fn listen_rustls(
self,
lst: TcpListener,
config: RustlsServerConfig
) -> Result<Self>
[src]
self,
lst: TcpListener,
config: RustlsServerConfig
) -> Result<Self>
Use listener for accepting incoming tls connection requests
This method sets alpn protocols to "h2" and "http/1.1"
pub fn bind<A: ToSocketAddrs>(self, addr: A) -> Result<Self>
[src]
The socket address to bind
To bind multiple addresses this method can be called multiple times.
pub fn bind_openssl<A>(
self,
addr: A,
builder: SslAcceptorBuilder
) -> Result<Self> where
A: ToSocketAddrs,
[src]
self,
addr: A,
builder: SslAcceptorBuilder
) -> Result<Self> where
A: ToSocketAddrs,
Start listening for incoming tls connections.
This method sets alpn protocols to "h2" and "http/1.1"
pub fn bind_rustls<A: ToSocketAddrs>(
self,
addr: A,
config: RustlsServerConfig
) -> Result<Self>
[src]
self,
addr: A,
config: RustlsServerConfig
) -> Result<Self>
Start listening for incoming tls connections.
This method sets alpn protocols to "h2" and "http/1.1"
pub fn listen_uds(self, lst: UnixListener) -> Result<Self>
[src]
Start listening for unix domain (UDS) connections on existing listener.
pub fn bind_uds<A>(self, addr: A) -> Result<Self> where
A: AsRef<Path>,
[src]
A: AsRef<Path>,
Start listening for incoming unix domain connections.
impl<F, I, S, B> HttpServer<F, I, S, B> where
F: Fn() -> I + Send + Clone + 'static,
I: IntoServiceFactory<S>,
S: ServiceFactory<Config = AppConfig, Request = Request>,
S::Error: Into<Error>,
S::InitError: Debug,
S::Response: Into<Response<B>>,
S::Service: 'static,
B: MessageBody,
[src]
F: Fn() -> I + Send + Clone + 'static,
I: IntoServiceFactory<S>,
S: ServiceFactory<Config = AppConfig, Request = Request>,
S::Error: Into<Error>,
S::InitError: Debug,
S::Response: Into<Response<B>>,
S::Service: 'static,
B: MessageBody,
pub fn run(self) -> Serverⓘ
[src]
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 Actix
system is not yet
configured.
use std::io; use actix_web::{web, App, HttpResponse, HttpServer}; #[actix_rt::main] async fn main() -> io::Result<()> { HttpServer::new(|| App::new().service(web::resource("/").to(|| HttpResponse::Ok()))) .bind("127.0.0.1:0")? .run() .await }
Auto Trait Implementations
impl<F, I, S, B> !RefUnwindSafe for HttpServer<F, I, S, B>
impl<F, I, S, B> Send for HttpServer<F, I, S, B> where
B: Send,
S: Send,
B: Send,
S: Send,
impl<F, I, S, B> !Sync for HttpServer<F, I, S, B>
impl<F, I, S, B> Unpin for HttpServer<F, I, S, B> where
B: Unpin,
F: Unpin,
S: Unpin,
B: Unpin,
F: Unpin,
S: Unpin,
impl<F, I, S, B> !UnwindSafe for HttpServer<F, I, S, B>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,