Struct aitch::servers::tiny_http::Server [−][src]
A tiny_http
server, which can serve a handler.
This server back-end uses tiny_http
to listen for incoming HTTP requests, call the provided
Handler
, and then return the response to the client.
The server uses the internal thread-pool of tiny_http
to construct HTTP requests/responses
from the underyling connection. The Handler
(and any handlers it may call) are spawned onto
a thread-pool managed by tokio-threadpool
, and so should not block requests from being
processed.
This server is unable to process streaming HTTP request or response bodies. The full request
body will be buffered in memory before the provided Handler
is called. The full response
body will be read from the returned Responder
before being sent to the client.
Users who wish to write asynchronous handlers, are encouraged to instead use the hyper
back-end.
Example
let addr = "127.0.0.1:3000".parse()?; aitch::servers::tiny_http::Server::new(addr, handler)?.run()
Methods
impl<H, ReqBody> Server<H, ReqBody> where
H: Handler<ReqBody>,
ReqBody: Body,
[src]
impl<H, ReqBody> Server<H, ReqBody> where
H: Handler<ReqBody>,
ReqBody: Body,
pub fn new(addr: SocketAddr, handler: H) -> Result<Server<H, ReqBody>>
[src]
pub fn new(addr: SocketAddr, handler: H) -> Result<Server<H, ReqBody>>
Creates a server which will listen on the provided SocketAddr
and handle requests using
the provided Handler
.
pub fn addr(&self) -> SocketAddr
[src]
pub fn addr(&self) -> SocketAddr
Returns the address that the server is listening on.
pub fn run(self) -> Result<()>
[src]
pub fn run(self) -> Result<()>
Starts and runs the server.