hack2-contrib 2011.6.10 → 2011.6.13
raw patch · 3 files changed
+22/−2 lines, 3 files
Files
- hack2-contrib.cabal +2/−1
- src/Hack2/Contrib/Middleware/XForwardedForToRemoteHost.hs +18/−0
- src/Hack2/Contrib/Utils.hs +2/−1
hack2-contrib.cabal view
@@ -1,5 +1,5 @@ Name: hack2-contrib-Version: 2011.6.10+Version: 2011.6.13 Build-type: Simple Synopsis: Hack2 contrib Description: Common middlewares and utilities that helps working with Hack2@@ -59,6 +59,7 @@ Hack2.Contrib.Middleware.UserMime -- Hack2.Contrib.Middleware.UTF8Body Hack2.Contrib.Middleware.Cascade+ Hack2.Contrib.Middleware.XForwardedForToRemoteHost Hack2.Contrib.Mime Hack2.Contrib.Request Hack2.Contrib.Response
+ src/Hack2/Contrib/Middleware/XForwardedForToRemoteHost.hs view
@@ -0,0 +1,18 @@+{-# LANGUAGE OverloadedStrings #-}++module Hack2.Contrib.Middleware.XForwardedForToRemoteHost (x_forwarded_for_to_remote_host) where++import Hack2+import Air.Env+import Prelude ()+import Data.ByteString.Lazy.Char8 ()++x_forwarded_for_to_remote_host :: Middleware+x_forwarded_for_to_remote_host app = \env ->+ case env.httpHeaders.lookup "x-forwarded-for" of+ Nothing -> app env+ Just ip -> + let newHackHeaders = ("RemoteHost", ip) : env.hackHeaders+ in+ + app - env {hackHeaders = newHackHeaders}
src/Hack2/Contrib/Utils.hs view
@@ -23,7 +23,8 @@ -- | usage: app.use [content_type, cache] use :: [Middleware] -> Middleware-use = reduce (<<<)+use [] = id+use xs = xs.reduce (<<<) -- use the get / put helper to deal with headers put :: (Eq a) => a -> b -> [(a, b)] -> [(a, b)]