Struct rust_xfinal::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.
§

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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