Skip to main content

SmugglingDetector

Struct SmugglingDetector 

Source
pub struct SmugglingDetector;
Expand description

请求走私检测器

在请求解析阶段对头部进行检测,识别不一致或恶意构造。

Implementations§

Source§

impl SmugglingDetector

Source

pub fn new() -> Self

创建检测器

Source

pub fn detect<N, V>( &self, headers: &[(N, V)], ) -> Result<(), (SmugglingKind, String)>
where N: AsRef<str>, V: AsRef<str>,

检测头部序列中的走私攻击

§参数
  • headers: [(name, value)] 头部列表(名称未规范化也可,内部会小写化)
§返回
  • Ok(()) : 通过检测
  • Err((SmugglingKind, String)) : 检测到的走私类型与说明
§性能

头部名称已小写化的调用方(如 crate::parser::Http1Parserparse_header_line 规范化后)应优先使用 Self::detect_already_lowercased, 跳过每头一次的 to_ascii_lowercase 分配。

Source

pub fn detect_already_lowercased<N, V>( &self, headers: &[(N, V)], ) -> Result<(), (SmugglingKind, String)>
where N: AsRef<str>, V: AsRef<str>,

检测头部序列中的走私攻击(假设头部名称已小写化)

Self::detect 语义一致,但假设调用方已将头部名称小写化 (如 crate::parser::Http1Parserparse_header_line 已执行 to_ascii_lowercase),跳过每头一次的 to_ascii_lowercase 分配。

§安全性

若传入未小写化的头部名称,匹配将失败(如 Content-Length 不会匹配 "content-length"),可能导致漏检。调用方必须保证名称已小写。

Source

pub fn detect_err<N, V>(&self, headers: &[(N, V)]) -> Result<(), Http1Error>
where N: AsRef<str>, V: AsRef<str>,

便捷:直接返回 Http1Error

Source

pub fn detect_err_already_lowercased<N, V>( &self, headers: &[(N, V)], ) -> Result<(), Http1Error>
where N: AsRef<str>, V: AsRef<str>,

便捷:直接返回 Http1Error(假设头部名称已小写化)

Self::detect_err 语义一致,但委托 Self::detect_already_lowercased, 跳过 to_ascii_lowercase 分配。调用方必须保证头部名称已小写化。

Trait Implementations§

Source§

impl Clone for SmugglingDetector

Source§

fn clone(&self) -> SmugglingDetector

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 Debug for SmugglingDetector

Source§

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

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

impl Default for SmugglingDetector

Source§

fn default() -> SmugglingDetector

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> 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 = 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.