Skip to main content

Http1ResponseEncoder

Struct Http1ResponseEncoder 

Source
pub struct Http1ResponseEncoder;
Expand description

HTTP/1.1 响应序列化器

将规范化响应序列化为符合 RFC 7230 的 HTTP/1.1 线路格式。

Implementations§

Source§

impl Http1ResponseEncoder

Source

pub fn encode( response: &CanonicalResponse, out: &mut Vec<u8>, ) -> Result<usize, ResponseSerializeError>

将 CanonicalResponse 序列化为 HTTP/1.1 线路格式

§参数
  • response: 规范化响应
  • out: 输出缓冲区(调用方预分配,零堆分配热路径)
§返回

写入的字节数,或序列化错误

§安全
  • 自动补全 Content-Length(若缺失且 body 非空且无 Transfer-Encoding)
  • 拒绝 CRLF 注入(二次校验)
  • 头部名称仅允许 RFC 7230 §3.2.6 token 字符
Source

pub fn encode_to_vec( response: &CanonicalResponse, ) -> Result<Vec<u8>, ResponseSerializeError>

便捷方法:序列化为新的 Vec

Trait Implementations§

Source§

impl Debug for Http1ResponseEncoder

Source§

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

Formats the value using the given formatter. 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.