X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResource%2FInternal.hs;h=d0d18b79afe6bcd5de2dbe4810fbac0e51d65120;hb=243b99439640480fc148d2e175247dacce04a222;hp=f5b54a94d35f0a74a0efacc6ad7a7d6f6bc4f93d;hpb=fffa09842d060c7d738084125dea07783d84aefe;p=Lucu.git diff --git a/Network/HTTP/Lucu/Resource/Internal.hs b/Network/HTTP/Lucu/Resource/Internal.hs index f5b54a9..d0d18b7 100644 --- a/Network/HTTP/Lucu/Resource/Internal.hs +++ b/Network/HTTP/Lucu/Resource/Internal.hs @@ -38,19 +38,20 @@ import Control.Concurrent import Control.Concurrent.STM import Control.Exception import Control.Monad hiding (mapM_) +import Control.Monad.Fix import Control.Monad.IO.Class import Control.Monad.Reader (ReaderT, runReaderT, ask) import Control.Monad.Unicode -import Data.Ascii (Ascii, CIAscii) -import qualified Data.Ascii as A +import Data.Ascii (Ascii, CIAscii, AsciiBuilder) import Data.ByteString (ByteString) import qualified Data.ByteString as BS import Data.Collections +import Data.Convertible.Base +import Data.Convertible.Instances.Text () import Data.List (intersperse, nub) import Data.Maybe import Data.Monoid import Data.Monoid.Unicode -import qualified Data.Text as T import Network.HTTP.Lucu.Abortion import Network.HTTP.Lucu.Abortion.Internal import Network.HTTP.Lucu.Config @@ -60,6 +61,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.Response.StatusCode import Network.HTTP.Lucu.Utils import Network.Socket #if defined(HAVE_SSL) @@ -75,7 +77,7 @@ newtype Rsrc a = Rsrc { unRsrc ∷ ReaderT NormalInteraction IO a } - deriving (Applicative, Functor, Monad, MonadIO) + deriving (Applicative, Functor, Monad, MonadFix, MonadIO) runRsrc ∷ Rsrc a → NormalInteraction → IO a runRsrc = runReaderT ∘ unRsrc @@ -179,10 +181,10 @@ spawnRsrc (Resource {..}) ni@(NI {..}) notAllowed ∷ Rsrc () notAllowed = do setStatus MethodNotAllowed setHeader "Allow" - $ A.fromAsciiBuilder + $ cs $ mconcat - $ intersperse (A.toAsciiBuilder ", ") - $ map A.toAsciiBuilder allowedMethods + $ intersperse (cs (", " ∷ Ascii) ∷ AsciiBuilder) + $ map cs allowedMethods allowedMethods ∷ [Ascii] allowedMethods = nub $ concat [ methods resGet ["GET"] @@ -201,7 +203,7 @@ spawnRsrc (Resource {..}) ni@(NI {..}) toAbortion e = case fromException e of Just abortion → abortion - Nothing → mkAbortion' InternalServerError $ T.pack $ show e + Nothing → mkAbortion' InternalServerError $ cs $ show e processException ∷ SomeException → IO () processException exc @@ -271,7 +273,7 @@ getRequest = niRequest <$> getInteraction -- main :: 'IO' () -- main = let tree :: 'Network.HTTP.Lucu.ResourceTree' -- tree = 'fromList' [ (["foo"], 'Network.HTTP.Lucu.greedy' resFoo) ] --- in 'Network.HTTP.Lucu.runHttpd' 'defaultConfig' $ 'Network.HTTP.Lucu.resourceMap' tree +-- in 'Network.withSocketsDo' '.' 'Network.HTTP.Lucu.runHttpd' 'defaultConfig' $ 'Network.HTTP.Lucu.resourceMap' tree -- -- resFoo :: 'Resource' -- resFoo = 'singleton' @@ -301,7 +303,7 @@ getChunk' n | n < 0 = fail ("getChunk: n must not be negative: " ⧺ show n) | n ≡ 0 = return (∅) | otherwise = do req ← getRequest - if reqMustHaveBody req then + if reqHasBody req then askForInput =≪ getInteraction else driftTo DecidingHeader *> return (∅)