INT

INTRO

The Network.N2O.Internal module contains request and context definition, state and N2O monad.

REQUEST

Listing 1. HTTP Request
type Header = (BS.ByteString, BS.ByteString) data Req = Req { reqPath :: BS.ByteString , reqMeth :: BS.ByteString , reqVers :: BS.ByteString , reqHead :: [Header] }
Listing 2. HTTP Response
data Resp = Resp { respCode :: Int , respHead :: [Header] , respBody :: BS.ByteString } deriving (Show)

CONTEXT

Listing 3. N2O Protocol Closure
data Event a = Init | Message a | Terminate deriving Show
Listing 4. N2O Protocol Result
data Result a = Reply a | Ok | Unknown | Empty deriving (Show, Eq)
Listing 5. N2O Context Record
data Context (f :: * -> *) a where Context :: { cxHandler :: Event a -> N2O f a (Result a) , cxReq :: Req , cxMiddleware :: [Context f a -> Context f a] , cxProtos :: [Proto f a] , cxActions :: BS.ByteString , cxDict :: M.Map BS.ByteString BS.ByteString } -> Context f a
Listing 6. N2O Context Constructor
mkCx = Context { cxReq = undefined , cxHandler = undefined , cxMiddleware = [] , cxProtos = [] , cxActions = "" , cxDict = M.empty }

MONAD

Listing 7. N2O Monad
type Proto (f :: * -> *) a = (f a) -> N2O f a (Result (f a)) type N2O f a = ReaderT (IORef (Context f a)) IO

put :: (B.Serialize bin) => BS.ByteString -> bin -> N2O f a ()

get :: (B.Serialize bin) => BS.ByteString -> N2O f a (Maybe bin)

getContext :: N2O f a (Context f a)

nop :: Result a

protoRun :: f a -> [Proto f a] -> N2O f a (Result (f a))

This module may refer to: INT, CORE