pub struct HttpContext { /* private fields */ }Expand description
网关HTTP上下文
Implementations§
Source§impl HttpContext
impl HttpContext
Sourcepub const REQUEST_ID: &'static str = ":req:id"
pub const REQUEST_ID: &'static str = ":req:id"
请求ID
Sourcepub const REQUEST_TS: &'static str = ":req:ts"
pub const REQUEST_TS: &'static str = ":req:ts"
请求时间戳,毫秒
Sourcepub const REQUEST_RAW_PARTS: &'static str = ":req:raw:parts"
pub const REQUEST_RAW_PARTS: &'static str = ":req:raw:parts"
请求的Parts(原始值,未经过网关处理),格式为http::request::Parts。 在请求生命周期内始终有效,不可变。
Sourcepub const RESPONSE_SERDE_PARTS: &'static str = ":resp:parts"
pub const RESPONSE_SERDE_PARTS: &'static str = ":resp:parts"
最终响应给客户端的Parts,格式为http::response::Parts
Sourcepub const RESPONSE_BODY_SIZE: &'static str = ":resp:parts:body_size"
pub const RESPONSE_BODY_SIZE: &'static str = ":resp:parts:body_size"
响应的Body大小
Sourcepub const IS_WEBSOCKET: &'static str = ":resp:is_ws"
pub const IS_WEBSOCKET: &'static str = ":resp:is_ws"
是否websocket
Sourcepub const MODEL_PROXY_MODEL: &'static str = ":model_proxy:model"
pub const MODEL_PROXY_MODEL: &'static str = ":model_proxy:model"
模型名称,仅适用于模型插件
Sourcepub const MODEL_PROXY_PROVIDER: &'static str = ":model_proxy:provider"
pub const MODEL_PROXY_PROVIDER: &'static str = ":model_proxy:provider"
模型提供商,仅适用于模型插件
Sourcepub const MODEL_USAGE_PROMPT_TOKENS: &'static str = ":model:usage:prompt_tokens"
pub const MODEL_USAGE_PROMPT_TOKENS: &'static str = ":model:usage:prompt_tokens"
模型调用 prompt token 数量
Sourcepub const MODEL_USAGE_COMPLETION_TOKENS: &'static str = ":model:usage:completion_tokens"
pub const MODEL_USAGE_COMPLETION_TOKENS: &'static str = ":model:usage:completion_tokens"
模型调用 completion token 数量
Sourcepub const MODEL_USAGE_TOTAL_TOKENS: &'static str = ":model:usage:total_tokens"
pub const MODEL_USAGE_TOTAL_TOKENS: &'static str = ":model:usage:total_tokens"
模型调用 total token 数量
Sourcepub const MODEL_TTFT_MS: &'static str = ":model:ttft_ms"
pub const MODEL_TTFT_MS: &'static str = ":model:ttft_ms"
模型调用首 Token 响应时间(毫秒)
Sourcepub const RESPONSE_STATUS_CODE: &'static str = ":resp:status_code"
pub const RESPONSE_STATUS_CODE: &'static str = ":resp:status_code"
响应状态码
pub fn new() -> Self
pub fn set_route(&mut self, route: Arc<Route>)
pub fn get_route(&self) -> Option<Arc<Route>>
pub fn set_routing_url(&mut self, url: String)
pub fn get_routing_url(&self) -> Option<&String>
pub fn insert_state<T: Serialize>(&self, key: &str, value: T)
pub fn get_state<T: DeserializeOwned>(&self, key: &str) -> Option<T>
pub fn remove_state(&self, key: &str)
pub fn insert_any_state<T: Any + Send + Sync>(&self, key: &str, value: T)
pub fn get_any_state<T: Any + Send + Sync>(&self, key: &str) -> Option<Arc<T>>
pub fn remove_any_state<T: Any + Send + Sync>(&self, key: &str)
pub fn exists_any_state(&self, key: &str) -> bool
Sourcepub fn request_id(&self) -> String
pub fn request_id(&self) -> String
获取请求ID
Sourcepub fn request_ts(&self) -> i64
pub fn request_ts(&self) -> i64
获取请求时间戳(网关收到请求的时间)
pub fn request_raw_parts(&self) -> Option<SerdeParts>
pub fn is_sse(&self) -> bool
pub fn is_websocket(&self) -> bool
Trait Implementations§
Source§impl Debug for HttpContext
impl Debug for HttpContext
Auto Trait Implementations§
impl !RefUnwindSafe for HttpContext
impl !UnwindSafe for HttpContext
impl Freeze for HttpContext
impl Send for HttpContext
impl Sync for HttpContext
impl Unpin for HttpContext
impl UnsafeUnpin for HttpContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more