X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResource%2FInternal.hs;h=28c2b3e4af781b3aadb13a1a4200140026a7e394;hp=d5a14117f267a781d75908619de76592a3ab74c7;hb=667baf9f664ccc093241287ad727b2839290f456;hpb=b22e702f8161447a460847c6e6c97104c150534f diff --git a/Network/HTTP/Lucu/Resource/Internal.hs b/Network/HTTP/Lucu/Resource/Internal.hs index d5a1411..28c2b3e 100644 --- a/Network/HTTP/Lucu/Resource/Internal.hs +++ b/Network/HTTP/Lucu/Resource/Internal.hs @@ -42,7 +42,8 @@ import Control.Monad.Reader (ReaderT, runReaderT, ask) import Control.Monad.Unicode import Data.Ascii (Ascii, CIAscii) import qualified Data.Ascii as A -import qualified Data.ByteString as Strict +import Data.ByteString (ByteString) +import qualified Data.ByteString as BS import Data.Collections import Data.List (intersperse, nub) import Data.Maybe @@ -58,6 +59,7 @@ import Network.HTTP.Lucu.Interaction import Network.HTTP.Lucu.Postprocess import Network.HTTP.Lucu.Request import Network.HTTP.Lucu.Response +import Network.HTTP.Lucu.Utils import Network.Socket #if defined(HAVE_SSL) import OpenSSL.X509 @@ -266,18 +268,18 @@ getRequest = niRequest <$> getInteraction -- > -- pathInfo == ["bar", "baz"] -- > ... -- > } -getResourcePath ∷ Rsrc [Strict.ByteString] +getResourcePath ∷ Rsrc PathSegments getResourcePath = niResourcePath <$> getInteraction -- |@'getChunk' n@ attempts to read a chunk of request body up to @n@ -- bytes. You can incrementally read the request body by repeatedly -- calling this function. If there is nothing to be read anymore, --- 'getChunk' returns 'Strict.empty' and makes 'Rsrc' transit to --- the /Deciding Header/ state. -getChunk ∷ Int → Rsrc Strict.ByteString +-- 'getChunk' returns 'BS.empty' and makes 'Rsrc' transit to the +-- /Deciding Header/ state. +getChunk ∷ Int → Rsrc ByteString getChunk = (driftTo ReceivingBody *>) ∘ getChunk' -getChunk' ∷ Int → Rsrc Strict.ByteString +getChunk' ∷ Int → Rsrc ByteString getChunk' n | n < 0 = fail ("getChunk: n must not be negative: " ⧺ show n) | n ≡ 0 = return (∅) @@ -287,7 +289,7 @@ getChunk' n else driftTo DecidingHeader *> return (∅) where - askForInput ∷ NormalInteraction → Rsrc Strict.ByteString + askForInput ∷ NormalInteraction → Rsrc ByteString askForInput (NI {..}) = do -- Ask the RequestReader to get a chunk. liftIO $ atomically @@ -297,7 +299,7 @@ getChunk' n $ atomically $ takeTMVar niReceivedBody -- Have we got an EOF? - when (Strict.null chunk) + when (BS.null chunk) $ driftTo DecidingHeader return chunk