Skip to main content

powhttp_sdk/
http2.rs

1
2use serde::{Deserialize, Serialize};
3use crate::shared::{NamedU8, NamedU16, NamedU32, Side};
4
5/// An HTTP/2 frame observed on one side of the connection.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8pub struct Http2Event {
9    pub side: Side,
10    pub frame: Frame,
11}
12
13/// A parsed HTTP/2 frame with its flags and payload.
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[serde(rename_all = "camelCase")]
16pub struct Frame {
17    pub flags: Flags,
18    pub payload: Payload,
19}
20
21/// HTTP/2 frame flags with the raw byte value and the named flags that are set.
22#[derive(Debug, Clone, Serialize, Deserialize)]
23#[serde(rename_all = "camelCase")]
24pub struct Flags {
25    pub value: u8,
26    pub defined: Vec<NamedU8>,
27}
28
29/// The frame-type–specific payload of an HTTP/2 frame.
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(tag = "type", rename_all = "snake_case", content = "content")]
32pub enum Payload {
33    Data(Data),
34    Headers(Headers),
35    Priority(Priority),
36    RstStream(RstStream),
37    Settings(Settings),
38    PushPromise(PushPromise),
39    Ping(Ping),
40    GoAway(GoAway),
41    WindowUpdate(WindowUpdate),
42    Continuation(Continuation),
43    Unknown(UnknownPayload)
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(rename_all = "camelCase")]
48pub struct Data {
49    pub padding_len: Option<usize>,
50    #[serde(with = "hex")]
51    pub data: Vec<u8>,
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
55#[serde(rename_all = "camelCase")]
56pub struct Headers {
57    pub padding_len: Option<usize>,
58    pub priority_info: Option<Priority>,
59    #[serde(with = "hex")]
60    pub header_block_fragment: Vec<u8>,
61}
62
63#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
64#[serde(rename_all = "camelCase")]
65pub struct Priority {
66    pub is_exclusive: bool,
67    pub stream_dependency: u32,
68    pub weight: u8,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize)]
72#[serde(rename_all = "camelCase")]
73pub struct RstStream {
74    pub error_code: NamedU32,
75}
76
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(rename_all = "camelCase")]
79pub struct Settings {
80    pub settings: Vec<SettingParameter>,
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
84#[serde(rename_all = "camelCase")]
85pub struct SettingParameter {
86    pub identifier: NamedU16,
87    pub value: u32,
88}
89
90#[derive(Debug, Clone, Serialize, Deserialize)]
91#[serde(rename_all = "camelCase")]
92pub struct PushPromise {
93    pub padding_len: Option<usize>,
94    pub promised_stream_id: u32,
95    #[serde(with = "hex")]
96    pub header_block_fragment: Vec<u8>,
97}
98
99#[derive(Debug, Clone, Serialize, Deserialize)]
100#[serde(rename_all = "camelCase")]
101pub struct Ping {
102    #[serde(with = "hex")]
103    pub data: Vec<u8>,
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
107#[serde(rename_all = "camelCase")]
108pub struct GoAway {
109    pub last_stream_id: u32,
110    pub error_code: NamedU32,
111    #[serde(with = "hex")]
112    pub debug_data: Vec<u8>,
113}
114
115#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
116#[serde(rename_all = "camelCase")]
117pub struct WindowUpdate {
118    pub window_size_increment: u32,
119}
120
121#[derive(Debug, Clone, Serialize, Deserialize)]
122#[serde(rename_all = "camelCase")]
123pub struct Continuation {
124    #[serde(with = "hex")]
125    pub field_block_fragment: Vec<u8>,
126}
127
128#[derive(Debug, Clone, Serialize, Deserialize)]
129#[serde(rename_all = "camelCase")]
130pub struct UnknownPayload {
131    #[serde(with = "hex")]
132    pub data: Vec<u8>,
133}