HttpServer

Struct HttpServer 

Source
pub struct HttpServer {
    pub routes: Routes,
    /* private fields */
}
Expand description

§HTTP Server

This struct stores the listener, which listens for incoming connections and handles them

Example:

let http_server = HttpServer::new("127.0.0.1", "8080").await.unwrap(); // Create a new http listener

Fields§

§routes: Routes

Implementations§

Source§

impl HttpServer

Source

pub async fn new(ip: &str, port: &str) -> Result<Self>

§New

Create a new server, with a given IP and port

Example

let http_server = HttpServer::new("127.0.0.1", "8080").await.unwrap();
Source

pub async fn new_tls( ip: &str, port: &str, cert_path: PathBuf, key_path: PathBuf, ) -> Result<Self>

§New TLS

Create a new server, with a given IP and port, and a TLS certificate and key

Example

let http_server = HttpServer::new_tls("127.0.0.1", "8080", "cert.pem", "key.pem").await.unwrap();
§Note

The certificate and key files must be in PEM and KEY formats respectively. The key must not be encrypted.

Source

pub async fn listen(&mut self) -> Result<(), &'static str>

§Listen

Listen for new connections.

Run handle_connection upon connection.

§Note

If you are using TLS, this function will not return until the server is shut down.

All errors will be printed to the console, instead of panicking.

Source

pub async fn set_read_buffer_size( &mut self, size: usize, ) -> Result<(), &'static str>

§Set Read Buffer Size

Set the read buffer size for the server. The default value is 8192 bytes.

Auto Trait Implementations§

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.