Skip to main content

Http2FrameBuilder

Struct Http2FrameBuilder 

Source
pub struct Http2FrameBuilder { /* private fields */ }
Expand description

Builder for a single HTTP/2 frame.

§Example

use stackforge_core::layer::http2::builder::Http2FrameBuilder;
use stackforge_core::layer::http2::frames::Http2FrameType;

let frame = Http2FrameBuilder::settings_ack().build();
assert_eq!(frame.len(), 9); // 9-byte header, empty payload

Implementations§

Source§

impl Http2FrameBuilder

Source

pub fn new(frame_type: Http2FrameType) -> Self

Create a new frame builder for the given frame type.

Source

pub fn flags(self, flags: u8) -> Self

Set the flags byte.

Source

pub fn add_flag(self, flag: u8) -> Self

Set an additional flag bit (OR with existing flags).

Source

pub fn stream_id(self, id: u32) -> Self

Set the stream ID.

Source

pub fn payload(self, data: Vec<u8>) -> Self

Set the frame payload.

Source

pub fn end_stream(self) -> Self

Set the END_STREAM flag (0x1).

Used with DATA and HEADERS frames.

Source

pub fn end_headers(self) -> Self

Set the END_HEADERS flag (0x4).

Used with HEADERS, PUSH_PROMISE, and CONTINUATION frames.

Source

pub fn build(&self) -> Vec<u8>

Build the frame into bytes.

Source

pub fn settings() -> Self

Create an empty SETTINGS frame (stream 0).

Source

pub fn settings_ack() -> Self

Create a SETTINGS ACK frame (stream 0, ACK flag set).

Source

pub fn settings_with_params(params: &[(u16, u32)]) -> Self

Create a SETTINGS frame with parameters.

Each entry is (settings_id, value). The payload is 6 bytes per entry.

Source

pub fn ping(data: [u8; 8]) -> Self

Create a PING frame with 8 bytes of opaque data.

Source

pub fn ping_ack(data: [u8; 8]) -> Self

Create a PING ACK frame (response to a PING).

Source

pub fn goaway(last_stream: u32, error_code: u32) -> Self

Create a GOAWAY frame.

§Arguments
  • last_stream: the last stream ID processed
  • error_code: the error code (see frames::error_codes)
Source

pub fn window_update(increment: u32, stream_id: u32) -> Self

Create a WINDOW_UPDATE frame.

§Arguments
  • increment: window size increment (1-2^31-1)
  • stream_id: stream ID (0 for connection-level)
Source

pub fn rst_stream(stream_id: u32, error_code: u32) -> Self

Create a RST_STREAM frame.

§Arguments
  • stream_id: the stream to reset
  • error_code: the error code
Source

pub fn headers_frame(stream_id: u32, hpack_data: Vec<u8>) -> Self

Create a HEADERS frame carrying HPACK-encoded header data.

Sets END_HEADERS by default. Use .flags() to override.

Source

pub fn headers_frame_final(stream_id: u32, hpack_data: Vec<u8>) -> Self

Create a HEADERS frame with END_STREAM + END_HEADERS flags set.

Source

pub fn data_frame(stream_id: u32, data: Vec<u8>) -> Self

Create a DATA frame.

Source

pub fn data_frame_final(stream_id: u32, data: Vec<u8>) -> Self

Create a DATA frame with END_STREAM set.

Source

pub fn continuation(stream_id: u32, hpack_data: Vec<u8>) -> Self

Create a CONTINUATION frame.

Source

pub fn continuation_final(stream_id: u32, hpack_data: Vec<u8>) -> Self

Create a CONTINUATION frame with END_HEADERS set.

Source

pub fn priority_frame( stream_id: u32, exclusive: bool, stream_dep: u32, weight: u8, ) -> Self

Create a PRIORITY frame.

§Arguments
  • stream_id: the stream being prioritized
  • exclusive: exclusive dependency flag
  • stream_dep: stream dependency
  • weight: priority weight (0-255, actual weight = weight + 1)
Source

pub fn push_promise( stream_id: u32, promised_stream_id: u32, hpack_data: Vec<u8>, ) -> Self

Create a PUSH_PROMISE frame.

§Arguments
  • stream_id: the associated stream
  • promised_stream_id: the stream ID being promised
  • hpack_data: HPACK-encoded headers for the promised request

Trait Implementations§

Source§

impl Clone for Http2FrameBuilder

Source§

fn clone(&self) -> Http2FrameBuilder

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 Http2FrameBuilder

Source§

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

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

impl IntoLayerStackEntry for Http2FrameBuilder

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