Skip to main content

Http1Connection

Struct Http1Connection 

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

HTTP/1.1 连接

Implementations§

Source§

impl Http1Connection

Source

pub fn new(config: Http1Config) -> Self

创建连接

Source

pub fn state(&self) -> Http1ConnectionState

当前状态

Source

pub fn is_closed(&self) -> bool

是否关闭

Source

pub fn on_data( &mut self, data: &[u8], ) -> Result<(Option<HttpRequest>, usize), Http1Error>

输入数据,尝试解析请求

§返回
  • Ok(Some(req, body_consumed)): 已解析完整请求,可能包含 body 字节消耗
  • Ok((None, consumed)): 需要更多数据
  • Err(err): 协议错误(错误会自动关闭连接)
Source

pub fn body_complete(&mut self, body: Vec<u8>)

设置请求体已接收完成

Source

pub fn current_request(&self) -> Option<&HttpRequest>

获取当前请求

Source

pub fn response_sent(&mut self)

响应发送完成

Source

pub fn on_error(&mut self, _err: &Http1Error)

处理错误:关闭连接

Source

pub fn requests_handled(&self) -> u64

获取已处理请求数

Source

pub fn update_time(&mut self, now_ms: u64)

更新当前时间戳(由事件循环每周期调用)

必须在首次 Self::on_data 之前调用至少一次,否则 parser 的 first_byte_ms 不会被设置(note_activity 被跳过),Slowloris 空闲超时检测在首字节阶段不生效。调用后 time_initialized 置 true, 后续 on_data 才会向 parser 刷新活跃时间戳。

Source

pub fn check_timeout(&mut self) -> Result<(), Http1Error>

检查空闲超时(Slowloris 防护)

由事件循环在每个周期调用。如果请求解析超时,关闭连接。

Source

pub fn close(&mut self)

关闭连接

Trait Implementations§

Source§

impl Debug for Http1Connection

Source§

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

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

impl Default for Http1Connection

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.