hack-frontend-happstack 2009.6.2 → 2009.6.24
raw patch · 5 files changed
+137/−7 lines, 5 filesdep +networkdep −hack-frontend-monadcgidep −happstack-fastcgidep ~basePVP ok
version bump matches the API change (PVP)
Dependencies added: network
Dependencies removed: hack-frontend-monadcgi, happstack-fastcgi
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- Nemesis +36/−0
- changelog.md +14/−0
- hack-frontend-happstack.cabal +3/−3
- src/Hack/Frontend/Happstack.hs +6/−4
- src/Test.hs +78/−0
+ Nemesis view
@@ -0,0 +1,36 @@+nemesis = do+ + clean+ [ "**/*.hi"+ , "**/*.o"+ , "manifest"+ , "main"+ , "nemesis-tmp.*"+ , "Test"+ ]+ ++ desc "prepare cabal dist"+ task "dist" $ do+ sh "cabal clean"+ sh "cabal configure"+ sh "cabal sdist"+++ desc "put all .hs files in manifest"+ task "manifest" $ do+ sh "find . | grep 'hs$' > manifest"+++ desc "start console"+ task "i" (sh "ghci -isrc src/Hack/Frontend/Happstack.hs")++ desc "test"+ task "test" $ do+ sh "ghc --make -isrc src/Test.hs -o Test"+ sh "echo ready..."+ sh "./Test"+ + desc "show sloc"+ task "stat" $ do+ sh "cloc -match-f=hs$ --quiet src"
changelog.md view
@@ -1,3 +1,17 @@+2009.6.24+---------++### Fix++* internal url parse++2009.6.5+--------++### Fix++* do not convert to unicode in headers+ 2009.6.2 --------
hack-frontend-happstack.cabal view
@@ -1,5 +1,5 @@ Name: hack-frontend-happstack-Version: 2009.6.2+Version: 2009.6.24 Build-type: Simple Synopsis: hack-frontend-happstack Description:@@ -14,11 +14,11 @@ Cabal-version: >= 1.2 category: Web homepage: http://github.com/nfjinjing/hack/tree/master-data-files: readme.md, changelog.md+data-files: readme.md, changelog.md, Nemesis, src/Test.hs library ghc-options: -Wall- build-depends: base, happstack-fastcgi, hack-frontend-monadcgi, happstack-server, hack >= 5.19, bytestring, containers, utf8-string+ build-depends: base >= 4.0 && < 5, network, happstack-server, hack >= 5.19, bytestring, containers, utf8-string hs-source-dirs: src/ exposed-modules: Hack.Frontend.Happstack
src/Hack/Frontend/Happstack.hs view
@@ -2,7 +2,7 @@ import Happstack.Server import Happstack.Server.HTTP.Types (Request (..), Version (Version))-import qualified Data.ByteString.UTF8 as UBS+import qualified Data.ByteString.Char8 as S import qualified Happstack.Server as H import Happstack.Server.SURI (parse) import qualified Hack as Hack@@ -10,8 +10,8 @@ import Hack (http, pathInfo, scriptName, queryString, hackInput, serverName, serverPort, Application) import Data.Maybe import Data.Foldable (toList)+import Network.URI (escapeURIString, isAllowedInURI) --- | Converts a Happstack ServerPartT to a CGI handling function. serverPartToApp :: (ToMessage b) => ServerPartT IO b -> Application serverPartToApp = convert . processRequest @@ -32,7 +32,7 @@ -- | Sets all the headers coming from Happstack convertHeader :: HeaderPair -> (String, String)-convertHeader (HeaderPair k v) = (UBS.toString k, UBS.toString (last v))+convertHeader (HeaderPair k v) = (S.unpack k, S.unpack (last v)) -- | Converts one request into another toHappstackRequest :: Hack.Env -> Request@@ -40,8 +40,9 @@ tmpRequest { rqInputs = queryInput uri ++ bodyInput tmpRequest } where- uri = fromJust $ parse $ concat $ map (\f -> f env) + uri = fromJust $ parse $ escape_uri $ concat $ map (\f -> f env) [ serverName+ , const ":" , show . serverPort , scriptName , pathInfo@@ -59,6 +60,7 @@ , rqBody = Body $ hackInput env , rqPeer = (serverName env, serverPort env) }+ escape_uri = escapeURIString isAllowedInURI convertRequestMethod Hack.OPTIONS = OPTIONS convertRequestMethod Hack.GET = GET
+ src/Test.hs view
@@ -0,0 +1,78 @@+module Main where+ +import Happstack.Server+import Hack.Frontend.Happstack+import Hack.Handler.Happstack++import Hack.Contrib.Utils+import Hack.Contrib.Request hiding (content_type)+import Hack.Contrib.Response+import Hack.Contrib.Middleware.ContentType+import Hack.Contrib.Middleware.ContentLength+import Hack.Contrib.Middleware.ShowExceptions+import Hack.Contrib.Middleware.ShowStatus+import Hack.Contrib.Middleware.Static++import Hack.Contrib.Middleware.Lucky+import Hack.Contrib.Middleware.Lambda+import Hack.Contrib.Middleware.SimpleAccessLogger+import Hack.Contrib.Middleware.BounceFavicon+import Hack.Contrib.Middleware.ETag+import Hack.Contrib.Middleware.Inspect+import Hack.Contrib.Middleware.Debug+import qualified Hack.Contrib.Middleware.Head as H+++import MPS+import Prelude hiding ((.))++import Data.Default+++default_content_type = "text/plain; charset=UTF-8"++middleware_stack = + [ dummy_middleware+ + -- filter+ , bounce_favicon++ -- setup+ --, parse_multipart+ + -- debug+ -- , inspect+ , debug (\e r -> e.inputs.print)+ + -- completeness+ , content_length+ , content_type default_content_type+ -- , etag+ + -- debuging+ , show_exceptions Nothing+ , show_status+ + -- optimization+ -- , H.head+ + -- log+ -- , simple_access_logger Nothing+ + -- for fun+ , lucky+ , lambda+ + -- static serve+ , static (Just "db/public") ["/theme", "/images", "/plugin", "/favicon.ico"]+ + -- real app++ ]++impl = anyRequest $ ok $ toResponse "hello world"++app = use middleware_stack (serverPartToApp impl)++main = run app+