pub struct Http2Parser<'a> { /* private fields */ }Expand description
HTTP/2 Protocol Parser
Provides parsing capabilities for HTTP/2 requests and responses according to RFC 7540. Supports HPACK header compression and handles various frame types.
§Thread Safety
This parser is NOT thread-safe. Each thread should create its own instance.
The internal HPACK decoder maintains state and uses RefCell for interior mutability.
Implementations§
Source§impl<'a> Http2Parser<'a>
impl<'a> Http2Parser<'a>
pub fn new() -> Self
pub fn with_config(config: Http2Config) -> Self
Sourcepub fn parse_request(
&self,
data: &[u8],
) -> Result<Option<Http2Request>, Http2ParseError>
pub fn parse_request( &self, data: &[u8], ) -> Result<Option<Http2Request>, Http2ParseError>
Parse HTTP/2 request from binary data
Sourcepub fn parse_response(
&self,
data: &[u8],
) -> Result<Option<Http2Response>, Http2ParseError>
pub fn parse_response( &self, data: &[u8], ) -> Result<Option<Http2Response>, Http2ParseError>
Parse HTTP/2 response from binary data
Sourcepub fn parse_frames(
&self,
data: &[u8],
) -> Result<Vec<Http2Frame>, Http2ParseError>
pub fn parse_frames( &self, data: &[u8], ) -> Result<Vec<Http2Frame>, Http2ParseError>
Parse HTTP/2 frames from raw data
Parses all frames from the given data, handling connection preface if present. Returns a vector of parsed frames or an error if parsing fails.
Sourcepub fn parse_frames_with_offset(
&self,
data: &[u8],
) -> Result<(Vec<Http2Frame>, usize), Http2ParseError>
pub fn parse_frames_with_offset( &self, data: &[u8], ) -> Result<(Vec<Http2Frame>, usize), Http2ParseError>
Parse HTTP/2 frames from raw data and return the number of bytes consumed
This is a convenience method that returns both the parsed frames and the number of bytes consumed from the input buffer. Useful for tracking parsing progress when processing incremental data.
§Parameters
data: Raw HTTP/2 frame data (may include connection preface)
§Returns
Ok((frames, bytes_consumed))on successErr(Http2ParseError)on parsing failure
§Example
use huginn_net_http::http2_parser::Http2Parser;
let parser = Http2Parser::new();
let data = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n\x00\x00\x06\x04\x00\x00\x00\x00\x00";
match parser.parse_frames_with_offset(data) {
Ok((frames, bytes_consumed)) => {
println!("Parsed {} frames, consumed {} bytes", frames.len(), bytes_consumed);
}
Err(e) => eprintln!("Parsing error: {:?}", e),
}Sourcepub fn parse_frames_skip_preface(
&self,
data: &[u8],
) -> Result<(Vec<Http2Frame>, usize), Http2ParseError>
pub fn parse_frames_skip_preface( &self, data: &[u8], ) -> Result<(Vec<Http2Frame>, usize), Http2ParseError>
Parse HTTP/2 frames from raw data, automatically skipping the connection preface if present
This is a convenience method that handles the HTTP/2 connection preface automatically, making it easier to parse frames from raw connection data.
§Parameters
data: Raw HTTP/2 frame data (may include connection preface)
§Returns
Ok((frames, bytes_consumed))on success, wherebytes_consumedincludes the preface if presentErr(Http2ParseError)on parsing failure
§Example
use huginn_net_http::http2_parser::Http2Parser;
let parser = Http2Parser::new();
let data = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n\x00\x00\x06\x04\x00\x00\x00\x00\x00";
match parser.parse_frames_skip_preface(data) {
Ok((frames, bytes_consumed)) => {
println!("Parsed {} frames, consumed {} bytes (including preface)", frames.len(), bytes_consumed);
}
Err(e) => eprintln!("Parsing error: {:?}", e),
}HTTP/2 cookie parsing - handles multiple cookie headers according to RFC 7540