2019-05-16 03:00:10 +03:00
|
|
|
-- zuse: +http -----------------------------------------------------------------
|
|
|
|
|
|
|
|
module Vere.Http where
|
|
|
|
|
|
|
|
import ClassyPrelude
|
|
|
|
import Data.Noun
|
2019-06-26 03:15:49 +03:00
|
|
|
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
|
2019-06-26 03:15:49 +03:00
|
|
|
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
|
|
|
|
2019-06-26 03:15:49 +03:00
|
|
|
instance ToNoun H.StdMethod where
|
|
|
|
toNoun = toNoun . Cord . encodeUtf8 . tshow
|
|
|
|
|
2019-05-16 03:00:10 +03:00
|
|
|
data Request = Request
|
2019-06-26 03:15:49 +03:00
|
|
|
{ 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
|
2019-06-26 03:15:49 +03:00
|
|
|
{ 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)
|