SaRequest

Trait SaRequest 

Source
pub trait SaRequest {
    // Required methods
    fn get_header(&self, name: &str) -> Option<String>;
    fn get_cookie(&self, name: &str) -> Option<String>;
    fn get_param(&self, name: &str) -> Option<String>;
    fn get_path(&self) -> String;
    fn get_method(&self) -> String;

    // Provided methods
    fn get_headers(&self) -> HashMap<String, String> { ... }
    fn get_cookies(&self) -> HashMap<String, String> { ... }
    fn get_params(&self) -> HashMap<String, String> { ... }
    fn get_uri(&self) -> String { ... }
    fn get_body_json<T>(&self) -> Option<T>
       where T: for<'de> Deserialize<'de> { ... }
    fn get_client_ip(&self) -> Option<String> { ... }
    fn get_user_agent(&self) -> Option<String> { ... }
}
Expand description

请求上下文trait

各个Web框架需要为其Request类型实现这个trait

Required Methods§

Source

fn get_header(&self, name: &str) -> Option<String>

获取请求头

获取Cookie

Source

fn get_param(&self, name: &str) -> Option<String>

获取查询参数

Source

fn get_path(&self) -> String

获取请求路径

Source

fn get_method(&self) -> String

获取请求方法

Provided Methods§

Source

fn get_headers(&self) -> HashMap<String, String>

获取所有请求头

Source

fn get_cookies(&self) -> HashMap<String, String>

获取所有Cookie

Source

fn get_params(&self) -> HashMap<String, String>

获取所有查询参数

Source

fn get_uri(&self) -> String

获取请求URI

Source

fn get_body_json<T>(&self) -> Option<T>
where T: for<'de> Deserialize<'de>,

获取请求体(如果是JSON)

Source

fn get_client_ip(&self) -> Option<String>

获取客户端IP

Source

fn get_user_agent(&self) -> Option<String>

获取User-Agent

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<'a, State> SaRequest for TideRequestAdapter<'a, State>