pub struct Server {
pub addr: String,
pub handler: Option<Arc<dyn Handler>>,
pub read_timeout: Option<Duration>,
pub write_timeout: Option<Duration>,
pub idle_timeout: Option<Duration>,
pub max_header_bytes: usize,
pub max_body_bytes: Option<u64>,
/* private fields */
}Expand description
An HTTP/1.1 server. Mirrors Go’s http.Server.
Fields§
§addr: StringTCP address to listen on, e.g. "127.0.0.1:8080".
handler: Option<Arc<dyn Handler>>Request handler. None uses the global DefaultServeMux.
read_timeout: Option<Duration>§write_timeout: Option<Duration>§idle_timeout: Option<Duration>§max_header_bytes: usizeMaximum bytes consumed while reading request headers.
max_body_bytes: Option<u64>Maximum request body size in bytes. None means unlimited.
Requests with a known Content-Length exceeding this limit are rejected
with 413 before the handler runs. Chunked bodies are wrapped in a
capped reader that returns an error when the limit is exceeded.
Implementations§
Source§impl Server
impl Server
pub fn new(addr: impl Into<String>) -> Self
Sourcepub fn listen_and_serve(&self) -> Result<(), HttpError>
pub fn listen_and_serve(&self) -> Result<(), HttpError>
Bind, listen, and serve HTTP/1.1 requests.
Must be called from within a #[go_lib::main] body (goroutine context).
Blocks the calling goroutine until shutdown() is called or a fatal
listener error occurs. Port of Go’s (*Server).ListenAndServe.
Sourcepub fn listen_and_serve_tls(
&self,
cert_file: &str,
key_file: &str,
) -> Result<(), HttpError>
pub fn listen_and_serve_tls( &self, cert_file: &str, key_file: &str, ) -> Result<(), HttpError>
Bind, listen, and serve HTTPS/1.1 requests.
Equivalent to listen_and_serve but wraps each accepted connection in
a TLS session using the certificate and key loaded from cert_file and
key_file (PEM format).
Must be called from within a #[go_lib::main] body (goroutine context).
Port of Go’s (*Server).ListenAndServeTLS.
Sourcepub fn shutdown(&self)
pub fn shutdown(&self)
Stop accepting new connections and wait for all active connections to finish serving their current requests.
Returns only after the last in-flight handler has returned, so callers
can safely clean up resources after shutdown() completes.
Port of Go’s (*Server).Shutdown (simplified — no context deadline).