Struct rust_xfinal::HttpServer

source ·
pub struct HttpServer { /* private fields */ }

Implementations§

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

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

  • [unit: millisecond]

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

  • [unit: millisecond]

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

  • [unit: byte]

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

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

  • [unit: byte]

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

  • [unit: byte]

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

  • [unit: byte]

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

  • [unit: millisecond]

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

  • [unit: millisecond]

This method specifies the size of the websocket’s fragment

  • [unit: byte]

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

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 /*

Register a websocket router

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
Examples found in repository?
src/lib.rs (lines 406-408)
403
404
405
406
407
408
409
410
    fn not_found_default_if_not_set(&mut self) {
        let r = &self.router.get(&String::from("NEVER_FOUND_FOR_ALL"));
        if let None = *r {
            self.set_not_found(|_req: &Request, res: &mut Response| {
                res.write_state(404);
            });
        }
    }

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.