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