1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
use crate::solicit::frame::DataFrame;
use crate::solicit::frame::Frame;
use crate::solicit::frame::GoawayFrame;
use crate::solicit::frame::HeadersDecodedFrame;
use crate::solicit::frame::HttpFrame;
use crate::solicit::frame::HttpFrameDecoded;
use crate::solicit::frame::PingFrame;
use crate::solicit::frame::PriorityFrame;
use crate::solicit::frame::PushPromiseFrame;
use crate::solicit::frame::RawFrame;
use crate::solicit::frame::RstStreamFrame;
use crate::solicit::frame::SettingsFrame;
use crate::solicit::frame::WindowUpdateFrame;
use crate::solicit::stream_id::StreamId;
#[derive(Debug)]
pub enum HttpFrameStream {
Data(DataFrame),
Headers(HeadersDecodedFrame),
Priority(PriorityFrame),
RstStream(RstStreamFrame),
PushPromise(PushPromiseFrame),
WindowUpdate(WindowUpdateFrame),
}
impl HttpFrameStream {
#[allow(dead_code)]
pub fn into_frame(self) -> HttpFrameDecoded {
match self {
HttpFrameStream::Headers(f) => HttpFrameDecoded::Headers(f),
HttpFrameStream::Data(f) => HttpFrameDecoded::Data(f),
HttpFrameStream::Priority(f) => HttpFrameDecoded::Priority(f),
HttpFrameStream::WindowUpdate(f) => HttpFrameDecoded::WindowUpdate(f),
HttpFrameStream::RstStream(f) => HttpFrameDecoded::RstStream(f),
HttpFrameStream::PushPromise(f) => HttpFrameDecoded::PushPromise(f),
}
}
#[allow(dead_code)]
pub fn get_stream_id(&self) -> StreamId {
match self {
&HttpFrameStream::Data(ref f) => f.get_stream_id(),
&HttpFrameStream::Headers(ref f) => f.get_stream_id(),
&HttpFrameStream::Priority(ref f) => f.get_stream_id(),
&HttpFrameStream::WindowUpdate(ref f) => f.get_stream_id(),
&HttpFrameStream::RstStream(ref f) => f.get_stream_id(),
&HttpFrameStream::PushPromise(ref f) => f.get_stream_id(),
}
}
#[allow(dead_code)]
pub fn is_end_of_stream(&self) -> bool {
match self {
&HttpFrameStream::Headers(ref f) => f.is_end_of_stream(),
&HttpFrameStream::Data(ref f) => f.is_end_of_stream(),
&HttpFrameStream::Priority(..) => false,
&HttpFrameStream::WindowUpdate(..) => false,
&HttpFrameStream::RstStream(..) => true,
&HttpFrameStream::PushPromise(..) => false,
}
}
}
#[derive(Debug)]
pub enum HttpFrameConn {
Settings(SettingsFrame),
Ping(PingFrame),
Goaway(GoawayFrame),
WindowUpdate(WindowUpdateFrame),
}
impl HttpFrameConn {
#[allow(dead_code)]
pub fn into_frame(self) -> HttpFrame {
match self {
HttpFrameConn::Settings(f) => HttpFrame::Settings(f),
HttpFrameConn::Ping(f) => HttpFrame::Ping(f),
HttpFrameConn::Goaway(f) => HttpFrame::Goaway(f),
HttpFrameConn::WindowUpdate(f) => HttpFrame::WindowUpdate(f),
}
}
}
#[derive(Debug)]
pub enum HttpFrameClassified {
Stream(HttpFrameStream),
Conn(HttpFrameConn),
Unknown(RawFrame),
}
impl HttpFrameClassified {
pub fn from(frame: HttpFrameDecoded) -> Self {
match frame {
HttpFrameDecoded::Data(f) => HttpFrameClassified::Stream(HttpFrameStream::Data(f)),
HttpFrameDecoded::Headers(f) => {
HttpFrameClassified::Stream(HttpFrameStream::Headers(f))
}
HttpFrameDecoded::Priority(f) => {
HttpFrameClassified::Stream(HttpFrameStream::Priority(f))
}
HttpFrameDecoded::RstStream(f) => {
HttpFrameClassified::Stream(HttpFrameStream::RstStream(f))
}
HttpFrameDecoded::Settings(f) => HttpFrameClassified::Conn(HttpFrameConn::Settings(f)),
HttpFrameDecoded::PushPromise(f) => {
HttpFrameClassified::Stream(HttpFrameStream::PushPromise(f))
}
HttpFrameDecoded::Ping(f) => HttpFrameClassified::Conn(HttpFrameConn::Ping(f)),
HttpFrameDecoded::Goaway(f) => HttpFrameClassified::Conn(HttpFrameConn::Goaway(f)),
HttpFrameDecoded::WindowUpdate(f) => {
if f.get_stream_id() != 0 {
HttpFrameClassified::Stream(HttpFrameStream::WindowUpdate(f))
} else {
HttpFrameClassified::Conn(HttpFrameConn::WindowUpdate(f))
}
}
HttpFrameDecoded::Unknown(f) => HttpFrameClassified::Unknown(f),
}
}
}