packages feed

hack-frontend-monadcgi (empty) → 0.0.0

raw patch · 4 files changed

+84/−0 lines, 4 filesdep +basedep +bytestringdep +cgisetup-changed

Dependencies added: base, bytestring, cgi, containers, hack

Files

+ Hack/Frontend/MonadCGI.hs view
@@ -0,0 +1,35 @@+module Hack.Frontend.MonadCGI+    ( cgiToApp+    ) where++import Hack+import Network.CGI.Monad+import Network.CGI.Protocol++import qualified Data.Map as Map+import qualified Data.ByteString.Lazy as BS++safeRead :: Read a => a -> String -> a+safeRead d s = case reads s of+                ((x, _):_) -> x+                _ -> d++cgiToApp :: CGI CGIResult -> Application+cgiToApp cgi env = do+    let vars = http env+        input = hackInput env+        (inputs, body') = decodeInput vars input+        req = CGIRequest+                { cgiVars = Map.fromList vars+                , cgiInputs = inputs+                , cgiRequestBody = body'+                }+    (headers'', output') <- runCGIT cgi req+    let output = case output' of+                    CGIOutput bs -> bs+                    CGINothing -> BS.empty+    let headers' = map (\(HeaderName x, y) -> (x, y)) headers''+    let status' = case lookup "Status" headers' of+                    Nothing -> 200+                    Just s -> safeRead 200 s+    return $ Response status' headers' output
+ LICENSE view
@@ -0,0 +1,25 @@+The following license covers this documentation, and the source code, except+where otherwise indicated.++Copyright 2008, Michael Snoyman. All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+  list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+  this list of conditions and the following disclaimer in the documentation+  and/or other materials provided with the distribution.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.lhs view
@@ -0,0 +1,7 @@+#!/usr/bin/env runhaskell++> module Main where+> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ hack-frontend-monadcgi.cabal view
@@ -0,0 +1,17 @@+name:            hack-frontend-monadcgi+version:         0.0.0+license:         BSD3+license-file:    LICENSE+author:          Michael Snoyman <michael@snoyman.com>+maintainer:      Michael Snoyman <michael@snoyman.com>+synopsis:        Allows programs written against MonadCGI to run with any hack handler.+category:        Web+stability:       stable+cabal-version:   >= 1.2+build-type:      Simple++library+    build-depends: base >= 3, bytestring, containers >= 0.2, cgi,+                   hack >= 2009.5.19+    exposed-modules: Hack.Frontend.MonadCGI+    ghc-options:     -Wall