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

50 lines
1.3 KiB
Haskell
Raw Normal View History

2019-05-16 03:00:10 +03:00
-- zuse: +http -----------------------------------------------------------------
module Vere.Http where
import ClassyPrelude
import Data.Noun
import Data.Noun.Atom
import Data.Noun.Poet
2019-05-16 03:00:10 +03:00
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
deriving (Eq, Ord, Show, Generic, ToNoun)
2019-05-16 03:00:10 +03:00
2019-05-24 02:58:18 +03:00
type Method = H.StdMethod
2019-05-16 03:00:10 +03:00
instance ToNoun H.StdMethod where
toNoun = toNoun . Cord . encodeUtf8 . tshow
2019-05-16 03:00:10 +03:00
data Request = Request
{ method :: Method
, url :: Text
, headerList :: [Header]
, body :: Maybe ByteString
}
deriving (Eq, Ord, Show, Generic, ToNoun)
2019-05-16 03:00:10 +03:00
data ResponseHeader = ResponseHeader
{ statusCode :: Word
, headers :: [Header]
}
deriving (Eq, Ord, Show, Generic, ToNoun)
data Event
= Started ResponseHeader -- [%start hdr (unit octs) ?]
| Received ByteString -- [%continue [~ octs] %.n]
| Done -- [%continue ~ %.y]
| Canceled -- %cancel
| Failed Text -- %cancel
deriving (Eq, Ord, Show, Generic, ToNoun)
2019-06-19 03:04:57 +03:00
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)