pub struct Http2Layer {
pub index: LayerIndex,
pub has_preface: bool,
}Expand description
HTTP/2 protocol layer view.
Represents one or more HTTP/2 frames within a packet buffer. The index
covers the portion of the buffer from the start of the HTTP/2 data
(preface or first frame header) to the end.
Note: A single Http2Layer may contain multiple frames. Use
frames::parse_all_frames or Http2Layer::all_frames to iterate them.
Fields§
§index: LayerIndexLayer boundary index within the packet buffer.
has_preface: boolWhether the layer begins with the HTTP/2 client connection preface.
Implementations§
Source§impl Http2Layer
impl Http2Layer
Sourcepub fn new(start: usize, end: usize, has_preface: bool) -> Self
pub fn new(start: usize, end: usize, has_preface: bool) -> Self
Create a new HTTP/2 layer from start/end offsets and a preface flag.
Sourcepub fn from_index(index: LayerIndex, has_preface: bool) -> Self
pub fn from_index(index: LayerIndex, has_preface: bool) -> Self
Create from an existing LayerIndex.
Sourcepub fn has_preface_at(buf: &[u8], offset: usize) -> bool
pub fn has_preface_at(buf: &[u8], offset: usize) -> bool
Check if buf starting at offset begins with the HTTP/2 preface.
Sourcepub fn frames_start(&self) -> usize
pub fn frames_start(&self) -> usize
Get the offset where frames begin (after the preface if present).
Sourcepub fn first_frame(&self, buf: &[u8]) -> Option<Http2Frame>
pub fn first_frame(&self, buf: &[u8]) -> Option<Http2Frame>
Get the first frame in this layer, skipping the preface if present.
Returns None if there are no frames or the buffer is too short.
Sourcepub fn all_frames(&self, buf: &[u8]) -> Vec<Http2Frame>
pub fn all_frames(&self, buf: &[u8]) -> Vec<Http2Frame>
Parse all frames in this layer’s buffer range.
Sourcepub fn header_len(&self, buf: &[u8]) -> usize
pub fn header_len(&self, buf: &[u8]) -> usize
Get the “header length” of this layer.
This returns the number of bytes that constitute the “header” portion:
- If only a preface: 24 bytes
- If a frame (no preface): 9 bytes (one frame header)
- If preface + at least one frame: 33 bytes (24 + 9)
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>>
Get a field value from the first frame by name.
Supported fields: frame_type, flags, stream_id, length.
Sourcepub fn set_field(
&self,
buf: &mut [u8],
name: &str,
value: FieldValue,
) -> Option<Result<(), FieldError>>
pub fn set_field( &self, buf: &mut [u8], name: &str, value: FieldValue, ) -> Option<Result<(), FieldError>>
Set a field value by name.
Currently only stream_id supports mutation. Other fields require
rebuilding the frame.
Sourcepub fn field_names() -> &'static [&'static str]
pub fn field_names() -> &'static [&'static str]
Get the static list of field names for this layer type.
Trait Implementations§
Source§impl Clone for Http2Layer
impl Clone for Http2Layer
Source§fn clone(&self) -> Http2Layer
fn clone(&self) -> Http2Layer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Http2Layer
impl Debug for Http2Layer
Source§impl From<Http2Layer> for LayerEnum
impl From<Http2Layer> for LayerEnum
Source§fn from(v: Http2Layer) -> LayerEnum
fn from(v: Http2Layer) -> LayerEnum
Source§impl Layer for Http2Layer
impl Layer for Http2Layer
Source§fn header_len(&self, data: &[u8]) -> usize
fn header_len(&self, data: &[u8]) -> usize
Source§fn field_names(&self) -> &'static [&'static str]
fn field_names(&self) -> &'static [&'static str]
Source§impl LayerDispatch for Http2Layer
impl LayerDispatch for Http2Layer
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 Http2Layer
impl RefUnwindSafe for Http2Layer
impl Send for Http2Layer
impl Sync for Http2Layer
impl Unpin for Http2Layer
impl UnsafeUnpin for Http2Layer
impl UnwindSafe for Http2Layer
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