Skip to main content

RequestContext

Struct RequestContext 

Source
pub struct RequestContext<'a> {
    pub token: &'a str,
    pub subject: &'a str,
    pub fingerprint: &'a str,
    pub location: Option<&'a str>,
    pub coords: Option<(f64, f64)>,
    pub signature: Option<&'a str>,
    pub at: Option<u64>,
}
Expand description

一次请求的全部输入,字段由调用方填写。

Fields§

§token: &'a str

调用方签发的 token 值。verify 中为空 ⇒ TokenUnknown。

§subject: &'a str

用户标识。仅 bind 使用,verify 完全忽略它:每请求校验的身份 一律取自服务端 SessionRecord(异地历史按 record.subject 聚合), 请求方提供的 subject 不可信。

因此中间件里传 subject: "" 是合法的 —— verify 不看这个字段 (bind 才要求非空)。也正因如此,绝不要把请求头里的用户标识 填进来当身份:现在它进不了判定,将来重构也未必。

§fingerprint: &'a str

客户端指纹(如 IP + User-Agent 的规范化拼接),登录时绑定。

§location: Option<&'a str>

区域标识,如 “CN-BJ”。由调用方用已有 geo 库从 IP 解析。

§coords: Option<(f64, f64)>

(纬度, 经度),用于「不可能旅行」判定。

§signature: Option<&'a str>

调用方算好的 MAC。

§at: Option<u64>

请求自称的时间(unix 秒,如 token 内嵌的 iat)。

Trait Implementations§

Source§

impl<'a> Clone for RequestContext<'a>

Source§

fn clone(&self) -> RequestContext<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for RequestContext<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for RequestContext<'a>

§

impl<'a> RefUnwindSafe for RequestContext<'a>

§

impl<'a> Send for RequestContext<'a>

§

impl<'a> Sync for RequestContext<'a>

§

impl<'a> Unpin for RequestContext<'a>

§

impl<'a> UnsafeUnpin for RequestContext<'a>

§

impl<'a> UnwindSafe for RequestContext<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.