Struct cosworth::prelude::server::HttpServer
source · pub struct HttpServer<H, F>where
H: 'static + IntoHttpHandler,
F: Fn() -> H + Send + Clone,{ /* private fields */ }
Expand description
An HTTP Server
By default it serves HTTP2 when HTTPs is enabled,
in order to change it, use ServerFlags
that can be provided
to acceptor service.
Implementations§
source§impl<H, F> HttpServer<H, F>where
H: 'static + IntoHttpHandler,
F: 'static + Fn() -> H + Send + Clone,
impl<H, F> HttpServer<H, F>where
H: 'static + IntoHttpHandler,
F: 'static + Fn() -> H + Send + Clone,
sourcepub fn new(factory: F) -> HttpServer<H, F>
pub fn new(factory: F) -> HttpServer<H, F>
Create new http server with application factory
sourcepub fn workers(self, num: usize) -> HttpServer<H, F>
pub fn workers(self, num: usize) -> HttpServer<H, F>
Set number of workers to start.
By default http server uses number of available logical cpu as threads count.
sourcepub fn backlog(self, num: i32) -> HttpServer<H, F>
pub fn backlog(self, num: i32) -> HttpServer<H, F>
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.
sourcepub fn maxconn(self, num: usize) -> HttpServer<H, F>
pub fn maxconn(self, num: usize) -> HttpServer<H, F>
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.
sourcepub fn maxconnrate(self, num: usize) -> HttpServer<H, F>
pub fn maxconnrate(self, num: usize) -> HttpServer<H, F>
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.
sourcepub fn keep_alive<T>(self, val: T) -> HttpServer<H, F>where
T: Into<KeepAlive>,
pub fn keep_alive<T>(self, val: T) -> HttpServer<H, F>where
T: Into<KeepAlive>,
Set server keep-alive setting.
By default keep alive is set to a 5 seconds.
sourcepub fn client_timeout(self, val: u64) -> HttpServer<H, F>
pub fn client_timeout(self, val: u64) -> HttpServer<H, F>
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.
sourcepub fn client_shutdown(self, val: u64) -> HttpServer<H, F>
pub fn client_shutdown(self, val: u64) -> HttpServer<H, F>
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.
sourcepub fn server_hostname(self, val: String) -> HttpServer<H, F>
pub fn server_hostname(self, val: String) -> HttpServer<H, F>
Set server host name.
Host name is used by application router aa a hostname for url generation. Check [ConnectionInfo](./dev/struct.ConnectionInfo. html#method.host) documentation for more information.
sourcepub fn system_exit(self) -> HttpServer<H, F>
pub fn system_exit(self) -> HttpServer<H, F>
Stop actix system.
SystemExit
message stops currently running system.
sourcepub fn disable_signals(self) -> HttpServer<H, F>
pub fn disable_signals(self) -> HttpServer<H, F>
Disable signal handling
sourcepub fn shutdown_timeout(self, sec: u16) -> HttpServer<H, F>
pub fn shutdown_timeout(self, sec: u16) -> HttpServer<H, F>
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.
sourcepub fn no_http2(self) -> HttpServer<H, F>
pub fn no_http2(self) -> HttpServer<H, F>
Disable HTTP/2
support
sourcepub fn addrs_with_scheme(&self) -> Vec<(SocketAddr, &str), Global> ⓘ
pub fn addrs_with_scheme(&self) -> Vec<(SocketAddr, &str), Global> ⓘ
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.
sourcepub fn listen(self, lst: TcpListener) -> HttpServer<H, F>
pub fn listen(self, lst: TcpListener) -> HttpServer<H, F>
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.
sourcepub fn listen_ssl(
self,
lst: TcpListener,
builder: SslAcceptorBuilder
) -> Result<HttpServer<H, F>, Error>
pub fn listen_ssl(
self,
lst: TcpListener,
builder: SslAcceptorBuilder
) -> Result<HttpServer<H, F>, Error>
Use listener for accepting incoming tls connection requests
This method sets alpn protocols to “h2” and “http/1.1”
sourcepub fn bind<S>(self, addr: S) -> Result<HttpServer<H, F>, Error>where
S: ToSocketAddrs,
pub fn bind<S>(self, addr: S) -> Result<HttpServer<H, F>, Error>where
S: ToSocketAddrs,
The socket address to bind
To bind multiple addresses this method can be called multiple times.
sourcepub fn bind_ssl<S>(
self,
addr: S,
builder: SslAcceptorBuilder
) -> Result<HttpServer<H, F>, Error>where
S: ToSocketAddrs,
pub fn bind_ssl<S>(
self,
addr: S,
builder: SslAcceptorBuilder
) -> Result<HttpServer<H, F>, Error>where
S: ToSocketAddrs,
Start listening for incoming tls connections.
This method sets alpn protocols to “h2” and “http/1.1”
source§impl<H, F> HttpServer<H, F>where
H: IntoHttpHandler,
F: Fn() -> H + Send + Clone,
impl<H, F> HttpServer<H, F>where
H: IntoHttpHandler,
F: Fn() -> H + Send + Clone,
sourcepub fn start(self) -> Addr<Server>
pub fn start(self) -> Addr<Server>
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.
extern crate actix_web;
extern crate actix;
use actix_web::{server, App, HttpResponse};
fn main() {
let sys = actix::System::new("example"); // <- create Actix system
server::new(|| App::new().resource("/", |r| r.h(|_: &_| HttpResponse::Ok())))
.bind("127.0.0.1:0")
.expect("Can not bind to 127.0.0.1:0")
.start();
sys.run(); // <- Run actix system, this method starts all async processes
}
sourcepub fn run(self)
pub fn run(self)
Spawn new thread and start listening for incoming connections.
This method spawns new thread and starts new actix system. Other than
that it is similar to start()
method. This method blocks.
This methods panics if no socket addresses get bound.
use actix_web::*;
fn main() {
HttpServer::new(|| App::new().resource("/", |r| r.h(|_| HttpResponse::Ok())))
.bind("127.0.0.1:0")
.expect("Can not bind to 127.0.0.1:0")
.run();
}
Auto Trait Implementations§
impl<H, F> !RefUnwindSafe for HttpServer<H, F>
impl<H, F> !Send for HttpServer<H, F>
impl<H, F> !Sync for HttpServer<H, F>
impl<H, F> Unpin for HttpServer<H, F>where
F: Unpin,
impl<H, F> !UnwindSafe for HttpServer<H, F>
Blanket Implementations§
source§impl<T> IntoSql for T
impl<T> IntoSql for T
source§fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
self
to an expression for Diesel’s query builder. Read moresource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
&self
to an expression for Diesel’s query builder. Read more