Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::protocols::http2::headers_frame Class Reference

HEADERS frame (RFC 7540 Section 6.2) More...

#include <frame.h>

Inheritance diagram for kcenon::network::protocols::http2::headers_frame:
Inheritance graph
Collaboration diagram for kcenon::network::protocols::http2::headers_frame:
Collaboration graph

Public Member Functions

 headers_frame (uint32_t stream_id, std::vector< uint8_t > header_block, bool end_stream=false, bool end_headers=true)
 Construct HEADERS frame.
 
auto is_end_stream () const -> bool
 Check if END_STREAM flag is set.
 
auto is_end_headers () const -> bool
 Check if END_HEADERS flag is set.
 
auto header_block () const -> std::span< const uint8_t >
 Get header block fragment.
 
- Public Member Functions inherited from kcenon::network::protocols::http2::frame
 frame ()=default
 Default constructor.
 
 frame (const frame_header &hdr, std::vector< uint8_t > payload)
 Construct frame with header and payload.
 
auto serialize () const -> std::vector< uint8_t >
 Serialize frame to bytes.
 
auto header () const -> const frame_header &
 Get frame header.
 
auto payload () const -> std::span< const uint8_t >
 Get frame payload.
 
virtual ~frame ()=default
 Virtual destructor.
 

Static Public Member Functions

static auto parse (const frame_header &hdr, std::span< const uint8_t > payload) -> Result< std::unique_ptr< headers_frame > >
 Parse HEADERS frame from raw bytes.
 
- Static Public Member Functions inherited from kcenon::network::protocols::http2::frame
static auto parse (std::span< const uint8_t > data) -> Result< std::unique_ptr< frame > >
 Parse frame from raw bytes.
 

Private Attributes

std::vector< uint8_t > header_block_
 Header block fragment.
 

Additional Inherited Members

- Protected Attributes inherited from kcenon::network::protocols::http2::frame
frame_header header_
 Frame header.
 
std::vector< uint8_t > payload_
 Frame payload.
 

Detailed Description

HEADERS frame (RFC 7540 Section 6.2)

HEADERS frames are used to open a stream and carry a header block fragment.

Definition at line 188 of file frame.h.

Constructor & Destructor Documentation

◆ headers_frame()

kcenon::network::protocols::http2::headers_frame::headers_frame ( uint32_t stream_id,
std::vector< uint8_t > header_block,
bool end_stream = false,
bool end_headers = true )

Construct HEADERS frame.

Parameters
stream_idStream identifier
header_blockHeader block fragment
end_streamTrue if this is the last frame in stream
end_headersTrue if this is the last header frame
priority_dataOptional priority information

Definition at line 272 of file frame.cpp.

274 : header_block_(std::move(header_block))
275 {
276 header_.stream_id = stream_id;
279
280 if (end_stream)
281 {
283 }
284
285 if (end_headers)
286 {
288 }
289
291 header_.length = static_cast<uint32_t>(payload_.size());
292 }
std::vector< uint8_t > payload_
Frame payload.
Definition frame.h:128
frame_header header_
Frame header.
Definition frame.h:127
auto header_block() const -> std::span< const uint8_t >
Get header block fragment.
Definition frame.cpp:348
std::vector< uint8_t > header_block_
Header block fragment.
Definition frame.h:230
uint32_t stream_id
Stream identifier (31 bits, MSB reserved)
Definition frame.h:58
uint32_t length
Payload length (24 bits)
Definition frame.h:55

References kcenon::network::protocols::http2::frame_flags::end_headers, kcenon::network::protocols::http2::frame_flags::end_stream, kcenon::network::protocols::http2::frame_header::flags, kcenon::network::protocols::http2::frame::header_, header_block_, kcenon::network::protocols::http2::headers, kcenon::network::protocols::http2::frame_header::length, kcenon::network::protocols::http2::frame_flags::none, kcenon::network::protocols::http2::frame::payload_, kcenon::network::protocols::http2::frame_header::stream_id, and kcenon::network::protocols::http2::frame_header::type.

Member Function Documentation

◆ header_block()

auto kcenon::network::protocols::http2::headers_frame::header_block ( ) const -> std::span<const uint8_t>

Get header block fragment.

Returns
Span of header block bytes

Definition at line 348 of file frame.cpp.

349 {
350 return header_block_;
351 }

References header_block_.

◆ is_end_headers()

auto kcenon::network::protocols::http2::headers_frame::is_end_headers ( ) const -> bool

Check if END_HEADERS flag is set.

Returns
True if this is the last header frame

Definition at line 343 of file frame.cpp.

344 {
346 }

References kcenon::network::protocols::http2::frame_flags::end_headers, kcenon::network::protocols::http2::frame_header::flags, and kcenon::network::protocols::http2::frame::header_.

◆ is_end_stream()

auto kcenon::network::protocols::http2::headers_frame::is_end_stream ( ) const -> bool

Check if END_STREAM flag is set.

Returns
True if this is the last frame in stream

Definition at line 338 of file frame.cpp.

339 {
341 }

References kcenon::network::protocols::http2::frame_flags::end_stream, kcenon::network::protocols::http2::frame_header::flags, and kcenon::network::protocols::http2::frame::header_.

◆ parse()

auto kcenon::network::protocols::http2::headers_frame::parse ( const frame_header & hdr,
std::span< const uint8_t > payload ) -> Result<std::unique_ptr<headers_frame>>
static

Parse HEADERS frame from raw bytes.

Parameters
hdrFrame header (must be HEADERS type)
payloadFrame payload
Returns
Result containing parsed HEADERS frame or error

Definition at line 294 of file frame.cpp.

296 {
297 if (hdr.stream_id == 0)
298 {
299 return error_info(7, "HEADERS frame must have non-zero stream ID", "http2");
300 }
301
302 std::vector<uint8_t> header_block;
303 size_t offset = 0;
304
305 if (hdr.flags & frame_flags::padded)
306 {
307 if (payload.empty())
308 {
309 return error_info(8, "Padded HEADERS frame must have pad length", "http2");
310 }
311
312 uint8_t pad_length = payload[0];
313 offset = 1;
314
315 if (payload.size() < offset + pad_length)
316 {
317 return error_info(9, "Invalid padding in HEADERS frame", "http2");
318 }
319
320 header_block.assign(payload.begin() + offset,
321 payload.end() - pad_length);
322 }
323 else
324 {
325 header_block.assign(payload.begin(), payload.end());
326 }
327
328 auto frame = std::make_unique<headers_frame>(
329 hdr.stream_id,
330 std::move(header_block),
331 hdr.flags & frame_flags::end_stream,
332 hdr.flags & frame_flags::end_headers
333 );
334
335 return frame;
336 }
frame()=default
Default constructor.
auto payload() const -> std::span< const uint8_t >
Get frame payload.
Definition frame.cpp:185
simple_error error_info

References kcenon::network::protocols::http2::frame_flags::end_headers, kcenon::network::protocols::http2::frame_flags::end_stream, and kcenon::network::protocols::http2::frame_flags::padded.

Referenced by kcenon::network::protocols::http2::frame::parse().

Here is the caller graph for this function:

Member Data Documentation

◆ header_block_

std::vector<uint8_t> kcenon::network::protocols::http2::headers_frame::header_block_
private

Header block fragment.

Definition at line 230 of file frame.h.

Referenced by header_block(), and headers_frame().


The documentation for this class was generated from the following files: