pub struct Server { /* private fields */ }
Expand description
The main class of this library.
Destroying this object will immediately close the listening socket and the reading
part of all the client’s connections. Requests that have already been returned by
the recv()
function will not close and the responses will be transferred to the client.
Implementations§
Source§impl Server
impl Server
Sourcepub fn http<A>(
addr: A,
) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>where
A: ToSocketAddrs,
pub fn http<A>(
addr: A,
) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>where
A: ToSocketAddrs,
Shortcut for a simple server on a specific address.
Sourcepub fn https<A>(
addr: A,
config: SslConfig,
) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>where
A: ToSocketAddrs,
pub fn https<A>(
addr: A,
config: SslConfig,
) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>where
A: ToSocketAddrs,
Shortcut for an HTTPS server on a specific address.
Sourcepub fn http_unix(
path: &Path,
) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>
pub fn http_unix( path: &Path, ) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>
Shortcut for a UNIX socket server at a specific path
Sourcepub fn new(
config: ServerConfig,
) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>
pub fn new( config: ServerConfig, ) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>
Builds a new server that listens on the specified address.
Sourcepub fn from_listener<L: Into<Listener>>(
listener: L,
ssl_config: Option<SslConfig>,
) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>
pub fn from_listener<L: Into<Listener>>( listener: L, ssl_config: Option<SslConfig>, ) -> Result<Server, Box<dyn Error + Send + Sync + 'static>>
Builds a new server using the specified TCP listener.
This is useful if you’ve constructed TcpListener using some less usual method
such as from systemd. For other cases, you probably want the new()
function.
Sourcepub fn incoming_requests(&self) -> IncomingRequests<'_> ⓘ
pub fn incoming_requests(&self) -> IncomingRequests<'_> ⓘ
Returns an iterator for all the incoming requests.
The iterator will return None
if the server socket is shutdown.
Sourcepub fn server_addr(&self) -> ListenAddr
pub fn server_addr(&self) -> ListenAddr
Returns the address the server is listening to.
Sourcepub fn num_connections(&self) -> usize
pub fn num_connections(&self) -> usize
Returns the number of clients currently connected to the server.
Sourcepub fn recv(&self) -> IoResult<Request>
pub fn recv(&self) -> IoResult<Request>
Blocks until an HTTP request has been submitted and returns it.