implemented high-level logic for strFromConn
This commit is contained in:
@@ -34,10 +34,16 @@ time.
|
||||
|
||||
module Network.Gemini.Capsule.Internal (
|
||||
readURL,
|
||||
sendResponse
|
||||
sendResponse,
|
||||
strFromConn,
|
||||
readMax,
|
||||
stripCRLF
|
||||
) where
|
||||
|
||||
import qualified Data.ByteString as BS
|
||||
import Data.Connection (Connection)
|
||||
import qualified Data.Text as T
|
||||
import Data.Text.Encoding (decodeUtf8')
|
||||
|
||||
import Network.Gemini.Capsule.Encoding
|
||||
import Network.Gemini.Capsule.Types
|
||||
@@ -76,6 +82,28 @@ strFromConn
|
||||
-> Connection a
|
||||
-- ^ The connection to read from
|
||||
-> IO (Maybe String)
|
||||
strFromConn = undefined
|
||||
strFromConn maxLen conn = do
|
||||
mbs <- readMax maxLen conn
|
||||
return $ do
|
||||
bs <- mbs
|
||||
txt <- case decodeUtf8' bs of
|
||||
Left _ -> Nothing
|
||||
Right s -> Just s
|
||||
stripCRLF $ T.unpack txt
|
||||
|
||||
-- | Reads from a connection up to a maximum number of bytes,
|
||||
-- returning 'Nothing' if the limit is exceeded
|
||||
readMax
|
||||
:: Int
|
||||
-- ^ the maximum number of bytes
|
||||
-> Connection a
|
||||
-- ^ the 'Connection' to read from
|
||||
-> IO (Maybe BS.ByteString)
|
||||
readMax = undefined
|
||||
|
||||
-- | Strips the CR/LF characters from the end of a string, retuning
|
||||
-- Nothing if they are not present
|
||||
stripCRLF :: String -> Maybe String
|
||||
stripCRLF = undefined
|
||||
|
||||
--jl
|
||||
|
||||
Reference in New Issue
Block a user