shrub/pkg/king/lib/Vere/Http.hs

54 lines
1.4 KiB
Haskell
Raw Normal View History

2019-05-16 03:00:10 +03:00
-- zuse: +http -----------------------------------------------------------------
module Vere.Http where
import ClassyPrelude
2019-07-02 05:51:26 +03:00
import Noun
import Arvo
2019-05-16 03:00:10 +03:00
import qualified Data.CaseInsensitive as CI
import qualified Network.HTTP.Types as HT
2019-05-24 02:58:18 +03:00
2019-06-28 00:28:58 +03:00
--------------------------------------------------------------------------------
2019-05-16 03:00:10 +03:00
data Request = Request
{ method :: Method
2019-07-22 21:10:27 +03:00
, url :: Cord
, headerList :: [Header]
2019-07-22 21:10:27 +03:00
, body :: Maybe Octs
}
2019-06-28 00:28:58 +03:00
deriving (Eq, Ord, Show)
2019-05-16 03:00:10 +03:00
2019-07-23 03:46:06 +03:00
data RawEvent
= Start ResponseHeader (Maybe Octs) Bool
| Continue (Maybe Octs) Bool
| Cancel
deriving (Eq, Ord, Show)
deriveNoun ''Request
deriveNoun ''RawEvent
--------------------------------------------------------------------------------
data Event
= Started ResponseHeader -- [%start hdr (unit octs) ?]
2019-07-22 21:10:27 +03:00
| Received Octs -- [%continue [~ octs] %.n]
| Done -- [%continue ~ %.y]
| Canceled -- %cancel
2019-07-22 21:10:27 +03:00
| Failed Cord -- %cancel
2019-06-28 00:28:58 +03:00
deriving (Eq, Ord, Show)
2019-06-28 00:28:58 +03:00
--------------------------------------------------------------------------------
2019-05-24 02:58:18 +03:00
convertHeaders :: [HT.Header] -> [Header]
convertHeaders = fmap f
where
f (k, v) = Header (Cord $ decodeUtf8 $ CI.foldedCase k)
(Cord $ decodeUtf8 v)
unconvertHeaders :: [Header] -> [HT.Header]
unconvertHeaders = fmap f
where
f (Header (Cord k) (Cord v)) = (CI.mk (encodeUtf8 k), (encodeUtf8 v))