hack2-contrib 2011.6.21 → 2011.10.12
raw patch · 9 files changed
+49/−33 lines, 9 filesdep −haskell98dep ~basedep ~enumeratorPVP ok
version bump matches the API change (PVP)
Dependencies removed: haskell98
Dependency ranges changed: base, enumerator
API changes (from Hackage documentation)
- Hack2.Contrib.AirBackports: b2u :: String -> String
- Hack2.Contrib.AirBackports: u2b :: String -> String
- Hack2.Contrib.Utils: l2s :: ByteString -> ByteString
- Hack2.Contrib.Utils: s2l :: ByteString -> ByteString
+ Hack2.Contrib.AirBackports: b2u, u2b :: String -> String
Files
- hack2-contrib.cabal +3/−4
- src/Hack2/Contrib/AirBackports.hs +2/−2
- src/Hack2/Contrib/Middleware/ContentLength.hs +6/−3
- src/Hack2/Contrib/Middleware/File.hs +28/−11
- src/Hack2/Contrib/Middleware/RegexpRouter.hs +1/−1
- src/Hack2/Contrib/Middleware/Static.hs +7/−3
- src/Hack2/Contrib/Middleware/URLMap.hs +1/−1
- src/Hack2/Contrib/Middleware/XForwardedForToRemoteHost.hs +1/−1
- src/Hack2/Contrib/Utils.hs +0/−7
hack2-contrib.cabal view
@@ -1,5 +1,5 @@ Name: hack2-contrib-Version: 2011.6.21+Version: 2011.10.12 Build-type: Simple Synopsis: Hack2 contrib Description: Common middlewares and utilities that helps working with Hack2@@ -16,10 +16,9 @@ library build-depends: - base >=4 && < 5+ base >=4 && < 100 , cgi , network- , haskell98 , old-locale , old-time , directory@@ -33,7 +32,7 @@ , utf8-string -- , ansi-wl-pprint , regexpr- , enumerator < 5+ , enumerator hs-source-dirs: src/
src/Hack2/Contrib/AirBackports.hs view
@@ -20,11 +20,11 @@ file_size :: String -> IO Integer-file_size path = withFile (path.u2b) ReadMode hFileSize+file_size path = withFile path ReadMode hFileSize file_mtime :: String -> IO UTCTime file_mtime path = - getModificationTime (path.u2b) ^ seconds ^ from_i ^ posixSecondsToUTCTime+ getModificationTime path ^ seconds ^ from_i ^ posixSecondsToUTCTime where seconds (TOD s _) = s now :: IO UTCTime
src/Hack2/Contrib/Middleware/ContentLength.hs view
@@ -10,15 +10,18 @@ import Air.Light import Prelude hiding ((.), (^), (>), (-)) - content_length :: Middleware content_length app = \env -> do response <- app env if should_size response then do- size <- response.body_bytestring ^ bytesize ^ show_bytestring- return - response.set_header _ContentLength size+ _body <- response.body_bytestring+ let size = _body.bytesize.show_bytestring+ return - + response+ .set_header _ContentLength size+ .set_body_bytestring _body else return - response
src/Hack2/Contrib/Middleware/File.hs view
@@ -40,22 +40,37 @@ let my_root = ( root ^ B.unpack ).fromMaybe cwd let path = my_root / makeRelative "/" (fname.B.unpack) - exist <- doesFileExist path+ -- puts - b2u - path+ + exist <- doesFileExist - b2u path if not exist- then path.B.pack.not_found+ then do+ -- puts "not exist"+ path.B.pack.not_found+ else do - can_read <- path.getPermissions ^ readable+ -- puts "exist"+ can_read <- path.b2u.getPermissions ^ readable+ + -- puts - "can_read is: " + show can_read if not can_read then path.B.pack.no_permission else path.serving where serving path = do- let file_enumerator = enumFile path+ -- puts "serving path"+ + let file_enumerator = enumFile - b2u path+ size <- path.b2u.file_size ^ from_i+ -- puts - "size is " + show size+ + mtime_str <- path.b2u.file_mtime ^ httpdate+ -- puts - "mtime_str is " + mtime_str let default_content_type = "application/octet-stream" let safe_lookup = lookup_mime_type > fromMaybe default_content_type@@ -70,14 +85,16 @@ .set_status 200 no_permission :: ByteString -> IO Response-no_permission path = return $- def- .set_status 404- .set_content_type _TextPlain- .set_content_length (msg.Lazy.length)- .set_body_bytestring msg+no_permission path = do+ putStrLn "no_permission"+ return - + def+ .set_status 404+ .set_content_type _TextPlain+ .set_content_length (msg.Lazy.length)+ .set_body_bytestring msg - where msg = "No permission: " + s2l path + "\n"+ where msg = "No permission: " + s2l path + "\n" not_found :: ByteString -> IO Response not_found path = return $
src/Hack2/Contrib/Middleware/RegexpRouter.hs view
@@ -7,7 +7,7 @@ import Hack2 import Hack2.Contrib.Utils import Hack2.Contrib.AirBackports-import List (find)+import Data.List (find) import Air import Prelude hiding ((.), (^), (>), (-)) import qualified Data.ByteString.Char8 as B
src/Hack2/Contrib/Middleware/Static.hs view
@@ -12,7 +12,7 @@ import Hack2 import Hack2.Contrib.Middleware.File (file) import Hack2.Contrib.Utils-import List (find, isPrefixOf)+import Data.List (find, isPrefixOf) import Air.Light import Prelude hiding ((.), (^), (>), (+)) import qualified Data.ByteString.Char8 as B@@ -27,5 +27,9 @@ let can_serve = my_urls.find ( `B.isPrefixOf` path ) .isJust if can_serve- then file root app env- else app env+ then do+ -- putStrLn "can serve"+ file root app env+ else do+ -- putStrLn "not valid prefix"+ app env
src/Hack2/Contrib/Middleware/URLMap.hs view
@@ -14,7 +14,7 @@ import Hack2 import Hack2.Contrib.Utils-import List (find, isPrefixOf)+import Data.List (find, isPrefixOf) import Air.Env hiding (Default, def) import Prelude () import qualified Data.ByteString.Char8 as B
src/Hack2/Contrib/Middleware/XForwardedForToRemoteHost.hs view
@@ -9,7 +9,7 @@ x_forwarded_for_to_remote_host :: Middleware x_forwarded_for_to_remote_host app = \env ->- case env.httpHeaders.lookup "x-forwarded-for" of+ case env.httpHeaders.lookup "X-Forwarded-For" of Nothing -> app env Just ip -> let newHackHeaders = ("RemoteHost", ip) : env.hackHeaders
src/Hack2/Contrib/Utils.hs view
@@ -38,13 +38,6 @@ bytes <- fromEnumerator enum return - toEnumerator - f bytes -l2s :: Lazy.ByteString -> Strict.ByteString-l2s = Strict.concat < Lazy.toChunks--s2l :: Strict.ByteString -> Lazy.ByteString-s2l = Lazy.fromChunks < return-- empty_app :: Application empty_app = return def