0 | module Http2Responder
  1 |
  2 | import Cont
  3 | import PGTypes
  4 |
  5 | public export
  6 | data FrameType
  7 |   = Data
  8 |   | Headers
  9 |   | Priority
 10 |   | RstStream
 11 |   | Settings
 12 |   | PushPromise
 13 |   | Ping
 14 |   | GoAway
 15 |   | WindowUpdate
 16 |   | Continuation
 17 |
 18 | public export
 19 | Show FrameType where
 20 |   show = \case
 21 |     Data => "Data"
 22 |     Headers => "Headers"
 23 |     Priority => "Priority"
 24 |     RstStream => "RstStream"
 25 |     Settings => "Settings"
 26 |     PushPromise => "PushPromise"
 27 |     Ping => "Ping"
 28 |     GoAway => "GoAway"
 29 |     WindowUpdate => "WindowUpdate"
 30 |     Continuation => "Continuation"
 31 |
 32 | public export
 33 | parseType : Bits8 -> Maybe FrameType
 34 | parseType n =
 35 |   case n of
 36 |     0 => Just Data
 37 |     1 => Just Headers
 38 |     2 => Just Priority
 39 |     3 => Just RstStream
 40 |     4 => Just Settings
 41 |     5 => Just PushPromise
 42 |     6 => Just Ping
 43 |     7 => Just GoAway
 44 |     8 => Just WindowUpdate
 45 |     9 => Just Continuation
 46 |     _ => Nothing
 47 |
 48 | public export
 49 | encodeFrameType : FrameType -> Bits8
 50 | encodeFrameType =
 51 |   \case
 52 |     Data         => 0
 53 |     Headers      => 1
 54 |     Priority     => 2
 55 |     RstStream    => 3
 56 |     Settings     => 4
 57 |     PushPromise  => 5
 58 |     Ping         => 6
 59 |     GoAway       => 7
 60 |     WindowUpdate => 8
 61 |     Continuation => 9
 62 |
 63 | public export
 64 | Eq FrameType where
 65 |   a == b = encodeFrameType a == encodeFrameType b
 66 |
 67 | public export
 68 | data Payload = MkPayload (List Bits8)
 69 |
 70 | public export
 71 | data Flags = MkFlags Bits8
 72 |
 73 | public export
 74 | record Frame where
 75 |   constructor MkFrame
 76 |   frameType : FrameType
 77 |   flags : Flags
 78 |   streamIdent : Bits32
 79 |   payload : Payload
 80 |
 81 | public export
 82 | data Header
 83 |   = MethodGet
 84 |   | MethodPost
 85 |   | PathSlash
 86 |   | SchemeHttp
 87 |   | SchemeHttps
 88 |   | ContentLength
 89 |   | ProxyAuthenticate
 90 |   | UserAgent
 91 |   | Literal Bits8 String
 92 |   | LiteralStr String String
 93 |   | StatusOk
 94 |
 95 | public export
 96 | Eq Header where
 97 |   MethodGet == MethodGet = True
 98 |   MethodPost == MethodPost = True
 99 |   PathSlash == PathSlash = True
100 |   SchemeHttp == SchemeHttp = True
101 |   SchemeHttps == SchemeHttps = True
102 |   ContentLength == ContentLength = True
103 |   UserAgent == UserAgent = True
104 |   Literal idx val == Literal idx2 val2 = idx == idx2 && val == val2
105 |   LiteralStr name val == LiteralStr name2 val2 = name == name2 && val == val2
106 |   StatusOk == StatusOk = True
107 |   _ == _ = False
108 |
109 | public export
110 | Show Header where
111 |   show MethodGet = "MethodGet"
112 |   show MethodPost = "MethodPost"
113 |   show PathSlash = "PathSlash"
114 |   show SchemeHttp = "SchemeHttp"
115 |   show SchemeHttps = "SchemeHttps"
116 |   show ContentLength = "ContentLength"
117 |   show ProxyAuthenticate = "ProxyAuthenticate"
118 |   show UserAgent = "UserAgent"
119 |   show (Literal idx lit) = "Literal " ++ show idx ++ " " ++ lit
120 |   show (LiteralStr name val) = "LiteralStr " ++ name ++ " " ++ val
121 |   show StatusOk = "StatusOk"
122 |
123 | public export
124 | InnerCont : Type -> Type
125 | InnerCont a = Cont (DIterator (List Bits8) (List Bits8) PgRows PgInput Void) a
126 |
127 | public export
128 | record Request where
129 |   constructor MkRequest
130 |   streamIdent: Bits32
131 |   path: String
132 |   body: List Bits8
133 |   headers: List Header
134 |