urbit/pkg/hs-urbit/lib/Vere/Http.hs

38 lines
970 B
Haskell
Raw Normal View History

2019-05-16 03:00:10 +03:00
-- zuse: +http -----------------------------------------------------------------
module Vere.Http where
import ClassyPrelude
import Data.Noun
2019-05-24 02:58:18 +03:00
import qualified Data.CaseInsensitive as CI
import qualified Network.HTTP.Types as HT
import qualified Network.HTTP.Types.Method as H
2019-05-16 03:00:10 +03:00
data Header = Header Text Text
2019-05-24 02:58:18 +03:00
type Method = H.StdMethod
2019-05-16 03:00:10 +03:00
data Request = Request
{ method :: Method
, url :: Text
, headerList :: [Header]
, body :: Maybe ByteString
}
data ResponseHeader = ResponseHeader
2019-05-18 00:52:12 +03:00
{ statusCode :: Int
2019-05-16 03:00:10 +03:00
, headers :: [Header]
}
2019-05-17 04:25:58 +03:00
data Event = Started ResponseHeader -- [%start hdr (unit octs) ?]
| Received ByteString -- [%continue [~ octs] %.n]
| Done -- [%continue ~ %.y]
| Canceled -- %cancel
2019-05-18 00:52:12 +03:00
| Failed Text -- %cancel
2019-05-24 02:58:18 +03:00
convertHeaders :: [HT.Header] -> [Header]
convertHeaders = fmap f
where
f (k, v) = Header (decodeUtf8 (CI.original k)) (decodeUtf8 v)