X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResource%2FInternal.hs;h=0a1f89f0c270288321ab9472b6ba4ce13872bb11;hb=a362be1c8664306b970c32e1df9b62081498feb1;hp=e8aa3ef6b555da151896040e3d9640e25e9cec6f;hpb=9668dc27a02b59d7bfb1e9e40af3d2619700ad69;p=Lucu.git diff --git a/Network/HTTP/Lucu/Resource/Internal.hs b/Network/HTTP/Lucu/Resource/Internal.hs index e8aa3ef..0a1f89f 100644 --- a/Network/HTTP/Lucu/Resource/Internal.hs +++ b/Network/HTTP/Lucu/Resource/Internal.hs @@ -41,6 +41,7 @@ import qualified Data.Ascii as A import qualified Data.ByteString as Strict import Data.List import Data.Maybe +import Data.Monoid import Data.Monoid.Unicode import qualified Data.Text as T import Network.HTTP.Lucu.Abortion @@ -52,7 +53,6 @@ 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 import OpenSSL.X509 import Prelude hiding (catch) @@ -166,12 +166,12 @@ spawnResource (ResourceDef {..}) ni@(NI {..}) _ → error $ "Unknown request method: " ⧺ show (reqMethod req) notAllowed ∷ Resource () - notAllowed - = setStatus MethodNotAllowed - *> - (setHeader "Allow" $ A.fromAsciiBuilder - $ joinWith ", " - $ map A.toAsciiBuilder allowedMethods) + notAllowed = do setStatus MethodNotAllowed + setHeader "Allow" + $ A.fromAsciiBuilder + $ mconcat + $ intersperse (A.toAsciiBuilder ", ") + $ map A.toAsciiBuilder allowedMethods allowedMethods ∷ [Ascii] allowedMethods = nub $ concat [ methods resGet ["GET"] @@ -329,9 +329,7 @@ setStatus sc -- body and thinks that the residual 10 bytes is a part of the header -- of the next response. setHeader ∷ CIAscii → Ascii → Resource () -setHeader name value - = do ni ← getInteraction - liftIO $ atomically $ go ni +setHeader name value = liftIO ∘ atomically ∘ go =≪ getInteraction where go ∷ NormalInteraction → STM () go (NI {..}) @@ -346,9 +344,7 @@ setHeader name value -- |@'deleteHeader' name@ deletes a response header @name@ if -- any. This function is not intended to be used so frequently. deleteHeader ∷ CIAscii → Resource () -deleteHeader name - = do ni ← getInteraction - liftIO $ atomically $ go ni +deleteHeader name = liftIO ∘ atomically ∘ go =≪ getInteraction where go ∷ NormalInteraction → STM () go (NI {..}) @@ -368,9 +364,7 @@ deleteHeader name -- \"Content-Type\" before applying this function. See -- 'setContentType'. putBuilder ∷ Builder → Resource () -putBuilder b - = do ni ← getInteraction - liftIO $ atomically $ go ni +putBuilder b = liftIO ∘ atomically ∘ go =≪ getInteraction where go ∷ NormalInteraction → STM () go ni@(NI {..}) @@ -383,9 +377,7 @@ putBuilder b putTMVar niBodyToSend b driftTo ∷ InteractionState → Resource () -driftTo newState - = do ni ← getInteraction - liftIO $ atomically $ driftTo' ni newState +driftTo = (getInteraction ≫=) ∘ ((liftIO ∘ atomically) ∘) ∘ flip driftTo' driftTo' ∷ NormalInteraction → InteractionState → STM () driftTo' ni@(NI {..}) newState