# [−][src]Struct actix_web::server::HttpServer

    pub struct HttpServer<H, F> where
        H: IntoHttpHandler + 'static,
        F: Fn() -> H + Send + Clone,  { /* fields omitted */ }

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.

## Methods

###

`impl<H, F> HttpServer<H, F> where H: IntoHttpHandler + 'static, F: Fn() -> H + Send + Clone + 'static,`

[src]

####

`pub fn new(factory: F) -> HttpServer<H, F>`

[src]

Create new http server with application factory

####

`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, num: 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 maxconn(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 maxconnrate(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 SSL 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(self, val: String) -> Self`

[src]

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.

####

`pub fn system_exit(self) -> Self`

[src]

Stop actix system.

`SystemExit` message stops currently running system.

####

`pub fn disable_signals(self) -> Self`

[src]

Disable signal handling

####

`pub fn shutdown_timeout(self, sec: u16) -> 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 no_http2(self) -> Self`

[src]

Disable `HTTP/2` support

####

`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) -> 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_tls(self, lst: TcpListener, acceptor: TlsAcceptor) -> Self`

[src]

Use listener for accepting incoming tls connection requests

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

####

`pub fn listen_ssl( self, lst: TcpListener, builder: SslAcceptorBuilder ) -> Result<Self>`

[src]

Use listener for accepting incoming tls connection requests

This method sets alpn protocols to "h2" and "http/1.1"

####

`pub fn bind<S: ToSocketAddrs>(self, addr: S) -> Result<Self>`

[src]

The socket address to bind

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

####

`pub fn bind_tls<S: ToSocketAddrs>( self, addr: S, acceptor: TlsAcceptor ) -> Result<Self>`

[src]

The ssl socket address to bind

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

####

`pub fn bind_ssl<S>(self, addr: S, builder: SslAcceptorBuilder) -> Result<Self> where S: ToSocketAddrs,`

[src]

Start listening for incoming tls connections.

This method sets alpn protocols to "h2" and "http/1.1"

###

`impl<H: IntoHttpHandler, F: Fn() -> H + Send + Clone> HttpServer<H, F>`

[src]

####

`pub fn start(self) -> Addr<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 addresses get bound.

This method requires to run within properly configured `Actix` system.

    extern crate actix_web;
    use actix_web::{actix, 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
    }

####

`pub fn run(self)`

[src]

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.

ⓘThis example is not tested

    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();
    }

####

`pub fn register(self, srv: Server) -> Server`

[src]

Register current http server as actix-net's server service

## Auto Trait Implementations

###

`impl<H, F> !Send for HttpServer<H, F>`

###

`impl<H, F> !Sync for HttpServer<H, F>`

## Blanket Implementations

###

`impl<T> From for T`

[src]

####

`fn from(t: T) -> T`

[src]

Performs the conversion.

###

`impl<T, U> Into for T where U: From<T>,`

[src]

####

`fn into(self) -> U`

[src]

Performs the conversion.

###

`impl<T, U> TryFrom for T where T: From<U>,`

[src]

#### `type Error = !`

🔬 This is a nightly-only experimental API. (`try_from`)

The type returned in the event of a conversion error.

####

`fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>`

[src]

🔬 This is a nightly-only experimental API. (`try_from`)

Performs the conversion.

###

`impl<T> Borrow for T where T: ?Sized,`

[src]

####

`fn borrow(&self) -> &T`

[src]

Immutably borrows from an owned value. Read more

###

`impl<T> BorrowMut for T where T: ?Sized,`

[src]

####

`fn borrow_mut(&mut self) -> &mut T`

[src]

Mutably borrows from an owned value. Read more

###

`impl<T, U> TryInto for T where U: TryFrom<T>,`

[src]

#### `type Error = <U as TryFrom<T>>::Error`

🔬 This is a nightly-only experimental API. (`try_from`)

The type returned in the event of a conversion error.

####

`fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>`

[src]

🔬 This is a nightly-only experimental API. (`try_from`)

Performs the conversion.

###

`impl<T> Any for T where T: 'static + ?Sized,`

[src]

####

`fn get_type_id(&self) -> TypeId`

[src]

🔬 This is a nightly-only experimental API. (`get_type_id`)

this method will likely be replaced by an associated static

Gets the `TypeId` of `self`. Read more

###

`impl<T> Erased for T`

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g. `str,u8` or `String,struct:Vec,test`)