Skip to main content

Server

Struct Server 

Source
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,
    /* private fields */
}
Expand description

An HTTP/1.1 server. Mirrors Go’s http.Server.

Fields§

§addr: String

TCP 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: usize

Maximum bytes consumed while reading request headers.

Implementations§

Source§

impl Server

Source

pub fn new(addr: impl Into<String>) -> Self

Source

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.

Source

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.

Source

pub fn shutdown(&self)

Signal the server to stop accepting new connections. Port of Go’s (*Server).Shutdown (simplified).

Auto Trait Implementations§

§

impl !Freeze for Server

§

impl !RefUnwindSafe for Server

§

impl !UnwindSafe for Server

§

impl Send for Server

§

impl Sync for Server

§

impl Unpin for Server

§

impl UnsafeUnpin for Server

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.