tests for runConnection
This commit is contained in:
@@ -97,18 +97,4 @@ adjustServerParams certRef params = let
|
||||
hooks' = hooks { onClientCertificate = certHook' }
|
||||
in params { serverHooks = hooks' }
|
||||
|
||||
runConnection
|
||||
:: C.Connection a
|
||||
-> GemHandler
|
||||
-> Maybe Certificate
|
||||
-> IO ()
|
||||
runConnection conn handler mCert =
|
||||
( readURL conn >>= \case
|
||||
Nothing -> return $ newGemResponse
|
||||
{ respStatus = 59
|
||||
, respMeta = "bad request"
|
||||
}
|
||||
Just url -> handler (newGemRequest url) { reqCert = mCert }
|
||||
) >>= sendResponse conn
|
||||
|
||||
--jl
|
||||
|
||||
@@ -33,6 +33,7 @@ time.
|
||||
{-# LANGUAGE LambdaCase #-}
|
||||
|
||||
module Network.Gemini.Capsule.Internal (
|
||||
runConnection,
|
||||
readURL,
|
||||
sendResponse,
|
||||
strFromConn,
|
||||
@@ -49,6 +50,7 @@ import qualified Data.ByteString.Lazy as BSL
|
||||
import Data.Connection (Connection, source)
|
||||
import qualified Data.Text as T
|
||||
import Data.Text.Encoding (decodeUtf8')
|
||||
import Data.X509 (Certificate)
|
||||
import qualified System.IO.Streams as S
|
||||
|
||||
import Network.Gemini.Capsule.Encoding
|
||||
@@ -60,6 +62,21 @@ import Network.Gemini.Capsule.Types
|
||||
inBufSize :: Int
|
||||
inBufSize = 1026
|
||||
|
||||
-- | process a request and return a response over a 'Connection'
|
||||
runConnection
|
||||
:: Connection a
|
||||
-> GemHandler
|
||||
-> Maybe Certificate
|
||||
-> IO ()
|
||||
runConnection conn handler mCert =
|
||||
( readURL conn >>= \case
|
||||
Nothing -> return $ newGemResponse
|
||||
{ respStatus = 59
|
||||
, respMeta = "bad request"
|
||||
}
|
||||
Just url -> handler (newGemRequest url) { reqCert = mCert }
|
||||
) >>= sendResponse conn
|
||||
|
||||
-- | Reads a 'GemURL' from a 'Connection'
|
||||
readURL
|
||||
:: Connection a
|
||||
|
||||
Reference in New Issue
Block a user