Struct rustful::server::Server
[−]
[src]
pub struct Server<R> { pub handlers: R, pub host: Host, pub threads: Option<usize>, pub keep_alive: Option<KeepAlive>, pub server: String, pub content_type: Mime, pub global: Global, pub context_filters: Vec<Box<ContextFilter>>, pub response_filters: Vec<Box<ResponseFilter>>, }
Used to set up and run a server.
let server_result = Server { host: 8080.into(), handlers: router, ..Server::default() }.run(); match server_result { Ok(_server) => {}, Err(e) => println!("could not start server: {}", e.description()) }
Fields
handlers: R
One or several response handlers.
host: Host
The host address and port where the server will listen for requests.
Default is 0.0.0.0:80
.
threads: Option<usize>
The number of threads to be used in the server thread pool. The default
(None
) will cause the server to optimistically use the formula
(num_cores * 5) / 4
.
keep_alive: Option<KeepAlive>
The server's keep-alive
policy. Setting this to Some(...)
will
allow keep-alive
connections with a timeout, and keeping it as None
will force connections to close after each request. Default is None
.
server: String
The content of the server header. Default is "rustful"
.
content_type: Mime
The default media type. Default is text/plain, charset: UTF-8
.
global: Global
Globally accessible data.
context_filters: Vec<Box<ContextFilter>>
The context filter stack.
response_filters: Vec<Box<ResponseFilter>>
The response filter stack.
Methods
impl<R: HandleRequest> Server<R>
[src]
impl<R: HandleRequest> Server<R>
pub fn new(handlers: R) -> Server<R>
[src]
pub fn new(handlers: R) -> Server<R>
Set up a new standard server. This can be useful when handlers
doesn't implement Default
:
let handler = |context: Context, response: Response| { //... }; let server_result = Server { host: 8080.into(), ..Server::new(handler) };
pub fn run(self) -> HttpResult<Listening>
[src]
pub fn run(self) -> HttpResult<Listening>
Start the server.
pub fn run_https<S: SslServer + Clone + Send + 'static>(
self,
ssl: S
) -> HttpResult<Listening>
[src]
pub fn run_https<S: SslServer + Clone + Send + 'static>(
self,
ssl: S
) -> HttpResult<Listening>
Start the server with SSL.
pub fn build(self) -> ServerInstance<R>
[src]
pub fn build(self) -> ServerInstance<R>
Build a runnable instance of the server.
Trait Implementations
impl<R: Default + HandleRequest> Default for Server<R>
[src]
impl<R: Default + HandleRequest> Default for Server<R>