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.