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 more