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: LayerIndexStart / end byte offsets of this HTTP message within the enclosing packet buffer.
Implementations§
Source§impl HttpLayer
impl HttpLayer
Sourcepub fn new(index: LayerIndex) -> Self
pub fn new(index: LayerIndex) -> Self
Create a new HttpLayer from a LayerIndex.
Sourcepub fn is_request(&self, buf: &[u8]) -> bool
pub fn is_request(&self, buf: &[u8]) -> bool
Returns true when the layer data looks like an HTTP request.
Sourcepub fn is_response(&self, buf: &[u8]) -> bool
pub fn is_response(&self, buf: &[u8]) -> bool
Returns true when the layer data looks like an HTTP response.
Sourcepub fn first_line<'a>(&self, buf: &'a [u8]) -> Option<&'a [u8]>
pub fn first_line<'a>(&self, buf: &'a [u8]) -> Option<&'a [u8]>
Return the first CRLF-terminated line of the HTTP message.
Sourcepub fn headers_end(buf: &[u8], start: usize) -> Option<usize>
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..].
Sourcepub fn method<'a>(&self, buf: &'a [u8]) -> Option<&'a str>
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.
Sourcepub fn uri<'a>(&self, buf: &'a [u8]) -> Option<&'a str>
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.
Sourcepub fn http_version<'a>(&self, buf: &'a [u8]) -> Option<&'a str>
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.
Sourcepub fn status_code(&self, buf: &[u8]) -> Option<u16>
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.
Sourcepub fn reason<'a>(&self, buf: &'a [u8]) -> Option<&'a str>
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.
Sourcepub fn header_value<'a>(&self, buf: &'a [u8], name: &str) -> Option<&'a str>
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.
Sourcepub fn body_offset(&self, buf: &[u8]) -> Option<usize>
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.
Sourcepub fn content_length(&self, buf: &[u8]) -> Option<usize>
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.
Sourcepub fn is_chunked(&self, buf: &[u8]) -> bool
pub fn is_chunked(&self, buf: &[u8]) -> bool
Return true when Transfer-Encoding: chunked is present.
Sourcepub fn summary_str(&self, buf: &[u8]) -> String
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"
Sourcepub fn http_header_len(&self, buf: &[u8]) -> usize
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.
Sourcepub fn field_names(&self) -> &'static [&'static str]
pub fn field_names(&self) -> &'static [&'static str]
Return the static list of field names for this layer.
Sourcepub fn get_field(
&self,
buf: &[u8],
name: &str,
) -> Option<Result<FieldValue, FieldError>>
pub fn get_field( &self, buf: &[u8], name: &str, ) -> Option<Result<FieldValue, FieldError>>
Return a field value by name.
| Field name | Type | Notes |
|---|---|---|
method | FieldValue::Bytes | requests only |
uri | FieldValue::Bytes | requests only |
version | FieldValue::Bytes | requests + responses |
status_code | FieldValue::U16 | responses only |
reason | FieldValue::Bytes | responses only |
Returns None for unrecognised field names or when the field does not
apply to the current message type.
Trait Implementations§
Source§impl Layer for HttpLayer
impl Layer for HttpLayer
Source§fn header_len(&self, data: &[u8]) -> usize
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 answers(&self, _data: &[u8], _other: &Self, _other_data: &[u8]) -> bool
fn answers(&self, _data: &[u8], _other: &Self, _other_data: &[u8]) -> bool
Source§fn extract_padding<'a>(&self, data: &'a [u8]) -> (&'a [u8], &'a [u8])
fn extract_padding<'a>(&self, data: &'a [u8]) -> (&'a [u8], &'a [u8])
Source§fn field_names(&self) -> &'static [&'static str]
fn field_names(&self) -> &'static [&'static str]
Source§impl LayerDispatch for HttpLayer
impl LayerDispatch for HttpLayer
Source§fn dispatch_kind(&self) -> LayerKind
fn dispatch_kind(&self) -> LayerKind
Source§fn dispatch_index(&self) -> &LayerIndex
fn dispatch_index(&self) -> &LayerIndex
Source§fn dispatch_summary(&self, buf: &[u8]) -> String
fn dispatch_summary(&self, buf: &[u8]) -> String
Source§fn dispatch_header_len(&self, buf: &[u8]) -> usize
fn dispatch_header_len(&self, buf: &[u8]) -> usize
Source§fn dispatch_field_names(&self) -> &'static [&'static str]
fn dispatch_field_names(&self) -> &'static [&'static str]
Source§fn dispatch_get_field(
&self,
buf: &[u8],
name: &str,
) -> Option<Result<FieldValue, FieldError>>
fn dispatch_get_field( &self, buf: &[u8], name: &str, ) -> Option<Result<FieldValue, FieldError>>
Source§fn dispatch_set_field(
&self,
_buf: &mut [u8],
_name: &str,
_value: FieldValue,
) -> Option<Result<(), FieldError>>
fn dispatch_set_field( &self, _buf: &mut [u8], _name: &str, _value: FieldValue, ) -> Option<Result<(), FieldError>>
Auto Trait Implementations§
impl Freeze for HttpLayer
impl RefUnwindSafe for HttpLayer
impl Send for HttpLayer
impl Sync for HttpLayer
impl Unpin for HttpLayer
impl UnsafeUnpin for HttpLayer
impl UnwindSafe for HttpLayer
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more