From 746c04c9e966429e95b82121b65e971a1b0e4ea8 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Thu, 13 Mar 2014 14:14:01 +0200 Subject: [PATCH] Use ByteString-based getEnvironment on *nix systems --- wai-extra/Network/Wai/Handler/CGI.hs | 10 +++++++++- wai-extra/wai-extra.cabal | 5 +++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/wai-extra/Network/Wai/Handler/CGI.hs b/wai-extra/Network/Wai/Handler/CGI.hs index 7437eafa..a54d78ab 100755 --- a/wai-extra/Network/Wai/Handler/CGI.hs +++ b/wai-extra/Network/Wai/Handler/CGI.hs @@ -13,7 +13,6 @@ module Network.Wai.Handler.CGI import Network.Wai import Network.Wai.Internal import Network.Socket (getAddrInfo, addrAddress) -import System.Environment (getEnvironment) import Data.Maybe (fromMaybe) import Control.Exception (mask) import qualified Data.ByteString.Char8 as B @@ -35,6 +34,15 @@ import qualified Data.CaseInsensitive as CI import Data.Monoid (mappend) import Data.Conduit +#if WINDOWS +import System.Environment (getEnvironment) +#else +import qualified System.Posix.Env.ByteString as Env + +getEnvironment :: IO [(String, String)] +getEnvironment = map (B.unpack *** B.unpack) `fmap` Env.getEnvironment +#endif + safeRead :: Read a => a -> String -> a safeRead d s = case reads s of diff --git a/wai-extra/wai-extra.cabal b/wai-extra/wai-extra.cabal index 1d4c1e3c..ec5ac48b 100644 --- a/wai-extra/wai-extra.cabal +++ b/wai-extra/wai-extra.cabal @@ -47,6 +47,11 @@ Library , word8 , lifted-base >= 0.1.2 + if os(windows) + cpp-options: -DWINDOWS + else + build-depends: unix + Exposed-modules: Network.Wai.Handler.CGI Network.Wai.Middleware.AcceptOverride Network.Wai.Middleware.Autohead