Skip to main content

HttpContext

Struct HttpContext 

Source
pub struct HttpContext { /* private fields */ }
Expand description

网关HTTP上下文

Implementations§

Source§

impl HttpContext

Source

pub const REQUEST_ID: &'static str = ":req:id"

请求ID

Source

pub const REQUEST_TS: &'static str = ":req:ts"

请求时间戳,毫秒

Source

pub const REQUEST_RAW_PARTS: &'static str = ":req:raw:parts"

请求的Parts(原始值,未经过网关处理),格式为http::request::Parts。 在请求生命周期内始终有效,不可变。

Source

pub const RESPONSE_SERDE_PARTS: &'static str = ":resp:parts"

最终响应给客户端的Parts,格式为http::response::Parts

Source

pub const RESPONSE_BODY_SIZE: &'static str = ":resp:parts:body_size"

响应的Body大小

Source

pub const IS_SSE: &'static str = ":resp:is_sse"

是否sse

Source

pub const IS_WEBSOCKET: &'static str = ":resp:is_ws"

是否websocket

Source

pub const MODEL_PROXY_MODEL: &'static str = ":model_proxy:model"

模型名称,仅适用于模型插件

Source

pub const MODEL_PROXY_PROVIDER: &'static str = ":model_proxy:provider"

模型提供商,仅适用于模型插件

Source

pub fn new() -> Self

Source

pub fn set_route(&mut self, route: Arc<Route>)

Source

pub fn get_route(&self) -> Option<Arc<Route>>

Source

pub fn set_routing_url(&mut self, url: String)

Source

pub fn get_routing_url(&self) -> Option<&String>

Source

pub fn insert_state<T: Serialize>(&self, key: &str, value: T)

Source

pub fn get_state<T: DeserializeOwned>(&self, key: &str) -> Option<T>

Source

pub fn remove_state(&self, key: &str)

Source

pub fn insert_any_state<T: Any + Send + Sync>(&self, key: &str, value: T)

Source

pub fn get_any_state<T: Any + Send + Sync>(&self, key: &str) -> Option<Arc<T>>

Source

pub fn remove_any_state<T: Any + Send + Sync>(&self, key: &str)

Source

pub fn exists_any_state<T: Any + Send + Sync>(&self, key: &str) -> bool

Source

pub fn request_id(&self) -> String

获取请求ID

Source

pub fn request_ts(&self) -> i64

获取请求时间戳(网关收到请求的时间)

Source

pub fn request_raw_parts(&self) -> Option<SerdeParts>

Source

pub fn is_sse(&self) -> bool

Source

pub fn is_websocket(&self) -> bool

Trait Implementations§

Source§

impl Debug for HttpContext

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for HttpContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.