Commit c6355019 authored by Yuanle Song's avatar Yuanle Song
Browse files

v0.1.1 bugfix: correct HTTP header names

header for PHP is modified in some way like WSGI. they prefix it with
HTTP_ and replace '-' by '_'. In haskell, I just need the raw header.
parent a516f0af
Loading
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -7,20 +7,20 @@ import qualified Data.Text.Lazy as L
import Web.Scotty

getClientIP1 :: ActionM (Maybe Text)
getClientIP1 = header "HTTP_CLIENT_IP"
getClientIP1 = header "CLIENT-IP"

getClientIP2 :: ActionM (Maybe Text)
getClientIP2 =
  fmap (maybe Nothing (Just . firstElement)) (header "HTTP_X_FORWARDED_FOR") where
  fmap (maybe Nothing (Just . firstElement)) (header "X-FORWARDED-FOR") where
      firstElement :: Text -> Text
      firstElement = head . L.splitOn ","

getClientIP3 :: ActionM (Maybe Text)
getClientIP3 = foldl1 (liftA2 (<|>)) $ map header ["HTTP_X_FORWARDED"
                                                  ,"HTTP_X_CLUSTER_CLIENT_IP"
                                                  ,"HTTP_FORWARDED_FOR"
                                                  ,"HTTP_FORWARDED"
                                                  ,"REMOTE_ADDR"]
getClientIP3 = foldl1 (liftA2 (<|>)) $ map header ["X-FORWARDED"
                                                  ,"X-CLUSTER-CLIENT-IP"
                                                  ,"FORWARDED-FOR"
                                                  ,"FORWARDED"
                                                  ,"REMOTE-ADDR"]

getClientIP :: ActionM ()
getClientIP = do
+1 −1
Original line number Diff line number Diff line
name:          get-client-ip
version:       0.1.0
version:       0.1.1
cabal-version: >= 1.8
build-type:    Simple