Skip to main content

HttpLayer

Struct HttpLayer 

Source
pub struct HttpLayer {
    pub index: LayerIndex,
}
Expand description

Lazy, index-based view of an HTTP/1.x message inside a packet buffer.

The same type represents either a request or a response; use HttpLayer::is_request / HttpLayer::is_response to disambiguate.

Fields§

§index: LayerIndex

Start / end byte offsets of this HTTP message within the enclosing packet buffer.

Implementations§

Source§

impl HttpLayer

Source

pub fn new(index: LayerIndex) -> Self

Create a new HttpLayer from a LayerIndex.

Source

pub fn is_request(&self, buf: &[u8]) -> bool

Returns true when the layer data looks like an HTTP request.

Source

pub fn is_response(&self, buf: &[u8]) -> bool

Returns true when the layer data looks like an HTTP response.

Source

pub fn first_line<'a>(&self, buf: &'a [u8]) -> Option<&'a [u8]>

Return the first CRLF-terminated line of the HTTP message.

Source

pub fn headers_end(buf: &[u8], start: usize) -> Option<usize>

Find the offset (relative to start) of the first byte after the \r\n\r\n header terminator. Returns None when the terminator is not found in buf[start..].

Source

pub fn method<'a>(&self, buf: &'a [u8]) -> Option<&'a str>

Return the HTTP method for a request (e.g. "GET", "POST").

Returns None for responses or malformed data.

Source

pub fn uri<'a>(&self, buf: &'a [u8]) -> Option<&'a str>

Return the request-URI for a request.

Returns None for responses or malformed data.

Source

pub fn http_version<'a>(&self, buf: &'a [u8]) -> Option<&'a str>

Return the HTTP version string (e.g. "HTTP/1.1") for either a request or a response.

Source

pub fn status_code(&self, buf: &[u8]) -> Option<u16>

Return the numeric status code for a response (e.g. 200, 404).

Returns None for requests or malformed data.

Source

pub fn reason<'a>(&self, buf: &'a [u8]) -> Option<&'a str>

Return the reason phrase for a response (e.g. "OK", "Not Found").

Returns None for requests or malformed data.

Source

pub fn header_value<'a>(&self, buf: &'a [u8], name: &str) -> Option<&'a str>

Perform a case-insensitive lookup for a header by name.

Returns the trimmed header value if found.

Source

pub fn body_offset(&self, buf: &[u8]) -> Option<usize>

Return the absolute byte offset (in buf) where the body starts, i.e. the byte immediately after \r\n\r\n.

Returns None when the header terminator is not present.

Source

pub fn content_length(&self, buf: &[u8]) -> Option<usize>

Parse the Content-Length header and return it as a usize.

Returns None when the header is absent or cannot be parsed.

Source

pub fn is_chunked(&self, buf: &[u8]) -> bool

Return true when Transfer-Encoding: chunked is present.

Source

pub fn summary_str(&self, buf: &[u8]) -> String

Generate a human-readable one-line summary:

  • Request : "HTTP GET /path HTTP/1.1"
  • Response: "HTTP 200 OK"
Source

pub fn http_header_len(&self, buf: &[u8]) -> usize

Return the byte length of the HTTP headers section, including the terminal \r\n\r\n, but excluding the body.

Returns 0 when the header block cannot be located.

Source

pub fn field_names(&self) -> &'static [&'static str]

Return the static list of field names for this layer.

Source

pub fn get_field( &self, buf: &[u8], name: &str, ) -> Option<Result<FieldValue, FieldError>>

Return a field value by name.

Field nameTypeNotes
methodFieldValue::Bytesrequests only
uriFieldValue::Bytesrequests only
versionFieldValue::Bytesrequests + responses
status_codeFieldValue::U16responses only
reasonFieldValue::Bytesresponses only

Returns None for unrecognised field names or when the field does not apply to the current message type.

Trait Implementations§

Source§

impl Clone for HttpLayer

Source§

fn clone(&self) -> HttpLayer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HttpLayer

Source§

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

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

impl Layer for HttpLayer

Source§

fn header_len(&self, data: &[u8]) -> usize

The header length for an HTTP layer is the number of bytes from the beginning of the message up to (and including) the \r\n\r\n header terminator. The body bytes are NOT included.

Source§

fn kind(&self) -> LayerKind

Get the kind of this layer
Source§

fn summary(&self, data: &[u8]) -> String

Get a human-readable summary of this layer
Source§

fn hashret(&self, _data: &[u8]) -> Vec<u8>

Compute a hash for packet matching.
Source§

fn answers(&self, _data: &[u8], _other: &Self, _other_data: &[u8]) -> bool

Check if this packet answers another packet.
Source§

fn extract_padding<'a>(&self, data: &'a [u8]) -> (&'a [u8], &'a [u8])

Extract padding from the packet.
Source§

fn field_names(&self) -> &'static [&'static str]

Get the list of field names for this layer

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> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V