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§
Sourcefn get_header(&self, name: &str) -> Option<String>
fn get_header(&self, name: &str) -> Option<String>
获取请求头
获取Cookie
Sourcefn get_method(&self) -> String
fn get_method(&self) -> String
获取请求方法
Provided Methods§
Sourcefn get_headers(&self) -> HashMap<String, String>
fn get_headers(&self) -> HashMap<String, String>
获取所有请求头
获取所有Cookie
Sourcefn get_params(&self) -> HashMap<String, String>
fn get_params(&self) -> HashMap<String, String>
获取所有查询参数
Sourcefn get_body_json<T>(&self) -> Option<T>where
T: for<'de> Deserialize<'de>,
fn get_body_json<T>(&self) -> Option<T>where
T: for<'de> Deserialize<'de>,
获取请求体(如果是JSON)
Sourcefn get_client_ip(&self) -> Option<String>
fn get_client_ip(&self) -> Option<String>
获取客户端IP
Sourcefn get_user_agent(&self) -> Option<String>
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.