Struct HttpServer

Source
pub struct HttpServer { /* private fields */ }

Implementations§

Source§

impl HttpServer

Source

pub fn create(end: EndPoint, count: u16) -> Self

create an instance of http server

  • end: use end_point![0.0.0.0:8080] to construct EndPoint
  • count: specify the size of thread pool
Source

pub fn set_read_timeout(&mut self, millis: u32)

This method specifies the value of time when waiting for the read from the client.

  • [unit: millisecond]
Source

pub fn set_write_timeout(&mut self, millis: u32)

This method specifies the value of time when waiting for the read of the client

  • [unit: millisecond]
Source

pub fn set_chunksize(&mut self, size: u32)

Specifiy each chunk size when responding to the client by using Chunked Transfer,

  • [unit: byte]
Source

pub fn open_server_log(&mut self, open: bool)

The switch to output the error in the connection the server has caught

Source

pub fn set_max_body_size(&mut self, size: usize)

Specify the maximum size of body in a connection the server can handle

  • [unit: byte]
Source

pub fn set_max_header_size(&mut self, size: usize)

Specify the maximum size of http header in a connection the server can handle

  • [unit: byte]
Source

pub fn set_read_buff_increase_size(&mut self, size: usize)

Specify the increased size of buffers used for taking the content of the stream in a connection

  • [unit: byte]
Source

pub fn set_ws_readtimeout(&mut self, millis: u32)

This method specifies the value of time when waiting for the websocket read from the client.

  • [unit: millisecond]
Source

pub fn set_ws_writetimeout(&mut self, millis: u32)

This method specifies the value of time when waiting for the websocket write to the client.

  • [unit: millisecond]
Source

pub fn set_ws_frame_size(&mut self, size: usize)

This method specifies the size of the websocket’s fragment

  • [unit: byte]
Source

pub fn run(&mut self)

To start a http server

  • This is a block method, which implies all set to the instance of HttpServer should precede the call of this method
Source

pub fn route<'a, T: SerializationMethods>( &'a mut self, methods: T, path: &'a str, ) -> RouterRegister<'_>

Register a router

  • methods: Http Method

allow the form: single method GET, or multiple methods [GET, HEAD]

  • path: Http Url to which the router respond
§Usage:

HttpServer::route(HttpServer::GET, “/”).reg(…)

  • the call of reg registers the action
  • the argument shall satisfy the trait Router
  • Router is automatically implemented for type fn and FnMut that takes two parameters &Request and & mut Response

HttpServer::route(HttpServer::GET, “/”).reg_with_middlewares(…)

  • register a router with a set of middlwares
  • The first argument is a set of middlwares
  • A middleware satisfies trait MiddleWare

In the above cases, the path can a wildcard url, such as /path/*

  • A valid wildcard path cannot be /*
Source

pub fn route_ws<'a>(&'a mut self, path: &'a str) -> WsRouterRegister<'a>

Register a websocket router

Source

pub fn set_not_found<F>(&mut self, f: F)
where F: Router + Send + Sync + 'static,

Specify the action when a request does not have a corresponding registered router

  • The framework has a preset action, you can overwrite it by using this method
  • The argument shall satisfy constraint: Router + Send + Sync + ’static

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V