pub struct HttpServer { /* private fields */ }
Implementations§
Source§impl HttpServer
impl HttpServer
Sourcepub fn create(end: EndPoint, count: u16) -> Self
pub fn create(end: EndPoint, count: u16) -> Self
create an instance of http server
- end: use
end_point![0.0.0.0:8080]
to constructEndPoint
- count: specify the size of thread pool
Sourcepub fn set_read_timeout(&mut self, millis: u32)
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]
Sourcepub fn set_write_timeout(&mut self, millis: u32)
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]
Sourcepub fn set_chunksize(&mut self, size: u32)
pub fn set_chunksize(&mut self, size: u32)
Specifiy each chunk size when responding to the client by using Chunked Transfer,
- [unit: byte]
Sourcepub fn open_server_log(&mut self, open: bool)
pub fn open_server_log(&mut self, open: bool)
The switch to output the error in the connection the server has caught
Sourcepub fn set_max_body_size(&mut self, size: usize)
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]
Sourcepub fn set_max_header_size(&mut self, size: usize)
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]
Sourcepub fn set_read_buff_increase_size(&mut self, size: usize)
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]
Sourcepub fn set_ws_readtimeout(&mut self, millis: u32)
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]
Sourcepub fn set_ws_writetimeout(&mut self, millis: u32)
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]
Sourcepub fn set_ws_frame_size(&mut self, size: usize)
pub fn set_ws_frame_size(&mut self, size: usize)
This method specifies the size of the websocket’s fragment
- [unit: byte]
Sourcepub fn run(&mut self)
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
Sourcepub fn route<'a, T: SerializationMethods>(
&'a mut self,
methods: T,
path: &'a str,
) -> RouterRegister<'_>
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
/*
Sourcepub fn route_ws<'a>(&'a mut self, path: &'a str) -> WsRouterRegister<'a>
pub fn route_ws<'a>(&'a mut self, path: &'a str) -> WsRouterRegister<'a>
Register a websocket router
Sourcepub fn set_not_found<F>(&mut self, f: F)
pub fn set_not_found<F>(&mut self, f: F)
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