X-Git-Url: http://git.cielonegro.org/gitweb.cgi?a=blobdiff_plain;f=Network%2FHTTP%2FLucu%2FResource%2FInternal.hs;h=9df36a601cf7dc460dd8b98f92ed084054719504;hb=ece223c516e66223ef1d5d8e6bbe4054a235d983;hp=a1ad95674aefc46e360dd86d221c061439137f4a;hpb=f402841101b4b84f263eea1a43c848f81c48ff93;p=Lucu.git diff --git a/Network/HTTP/Lucu/Resource/Internal.hs b/Network/HTTP/Lucu/Resource/Internal.hs index a1ad956..9df36a6 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) @@ -90,9 +90,9 @@ data ResourceDef = ResourceDef { -- resource path. If 'resGet' is Nothing, the system responds -- \"405 Method Not Allowed\" for GET requests. -- - -- It also runs for HEAD request if the 'resHead' is Nothing. In - -- this case 'output' and such like don't actually write a - -- response body. + -- It also runs for HEAD request if the 'resHead' is 'Nothing'. In + -- that case 'putChunk' and such don't actually write a response + -- body. , resGet ∷ !(Maybe (Resource ())) -- |A 'Resource' to be run when a HEAD request comes for the -- resource path. If 'resHead' is Nothing, the system runs @@ -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"] @@ -257,7 +257,7 @@ getRequest = niRequest <$> getInteraction -- > main = let tree = mkResTree [ (["foo"], resFoo) ] -- > in runHttpd defaultConfig tree [] -- > --- > resFoo = ResourceDef { +-- > resFoo = emptyResource { -- > resIsGreedy = True -- > , resGet = Just $ do requestURI <- getRequestURI -- > resourcePath <- getResourcePath @@ -266,7 +266,6 @@ getRequest = niRequest <$> getInteraction -- > -- resourcePath == ["foo"] -- > -- pathInfo == ["bar", "baz"] -- > ... --- > , ... -- > } getResourcePath ∷ Resource [Strict.ByteString] getResourcePath = niResourcePath <$> getInteraction @@ -362,7 +361,7 @@ deleteHeader name writeTVar niResponseHasCType False -- |Run a 'Builder' to construct a chunk, and write it to the response --- body. It is safe to apply this function to a 'Builder' producing an +-- body. It can be safely applied to a 'Builder' producing an -- infinitely long stream of octets. -- -- Note that you must first declare the response header