0 | module HTTP.Parser.Util
3 | import public Text.ILex
7 | public export %inline
11 | public export %inline
15 | public export %inline
16 | byte_questionmark : Bits8
17 | byte_questionmark = 63
19 | public export %inline
20 | byte_ampersand : Bits8
24 | hex : Bits8 -> Bits8
25 | hex b = if b < 10 then byte_0 + b else byte_A + b - 10
28 | escape : Bits8 -> ByteString
29 | escape b = pack [byte_percent, hex (shiftR b 4 .&. 0xf), hex (b .&. 0xf)]
37 | uriEscape : (Bits8 -> Bool) -> ByteString -> ByteString
38 | uriEscape p = go [<]
40 | go : SnocList ByteString -> ByteString -> ByteString
43 | (pre, BS 0 _) => fastConcat $
sx <>> [pre]
44 | (pre, BS (S k) bv) =>
46 | in go (sx :< pre :< escape b) (assert_smaller bs $
BS k $
tail bv)
54 | uriUnescape : ByteString -> ByteString
55 | uriUnescape = go [<]
57 | go : SnocList ByteString -> ByteString -> ByteString
59 | case break (byte_percent ==) bs of
60 | (pre, bs2@(BS (S (S (S k))) bv)) =>
61 | let b := cast $
16 * hexdigit (at bv 1) + hexdigit (at bv 2)
62 | in go (sx :< pre :< singleton b) (assert_smaller bs $
drop 3 bs2)
63 | (pre, _) => fastConcat $
sx <>> [pre]
72 | OCTETT = range (range 0x00 0xff)
80 | BIT = range $
range 48 49
84 | DIGIT = range $
range 0x30 0x39
88 | HEXDIG = DIGIT `union` (range (range 65 70) `union` range (range 97 102))
92 | CHAR = range $
range 0x01 0x7f
96 | CTL = range (range 0x00 0x1f) `union` singleton 0x7f
100 | VCHAR = range $
range 0x21 0x7e
104 | tokenChar = chars "!#$%&'*+-.^_`|~"
111 | public export %inline
113 | CR = Ch $
singleton 0x0d
115 | public export %inline
117 | LF = Ch $
singleton 0xa
123 | public export %inline
125 | DQUOTE = Ch $
singleton 0x22
127 | public export %inline
129 | HTAB = Ch $
singleton 0x09
131 | public export %inline
133 | SP = Ch $
singleton 0x20
142 | OWS = star $
SP <|> HTAB
149 | pctEncoded : RExp True
150 | pctEncoded = '%' >> Ch HEXDIG >> Ch HEXDIG