hack2-contrib 2014.4.14 → 2014.5.19
raw patch · 3 files changed
+53/−41 lines, 3 filesdep −cgiPVP ok
version bump matches the API change (PVP)
Dependencies removed: cgi
API changes (from Hackage documentation)
- Hack2.Contrib.Request: cookies :: Env -> [(ByteString, ByteString)]
- Hack2.Contrib.Request: inputs :: Env -> IO [(ByteString, ByteString)]
Files
- changelog.md +7/−0
- hack2-contrib.cabal +1/−7
- src/Hack2/Contrib/Request.hs +45/−34
changelog.md view
@@ -0,0 +1,7 @@+2014.5.19+---------++* get rid of CGI dependency+* removed from Request+ * inputs+ * cookies
hack2-contrib.cabal view
@@ -1,5 +1,5 @@ Name: hack2-contrib-Version: 2014.4.14+Version: 2014.5.19 Build-type: Simple Synopsis: Hack2 contrib Description: Common middlewares and utilities for Hack2@@ -18,7 +18,6 @@ build-depends: base >=4 && < 100- , cgi , network , old-locale , directory@@ -58,8 +57,3 @@ Hack2.Contrib.Request Hack2.Contrib.Response Hack2.Contrib.Utils-----
src/Hack2/Contrib/Request.hs view
@@ -9,13 +9,13 @@ import Hack2.Contrib.Constants import Hack2.Contrib.Utils import Air.Env hiding (Default, def)-import Network.CGI.Cookie-import Network.CGI.Protocol import Prelude () import qualified Data.ByteString.Char8 as B import Hack2.Contrib.AirBackports import Data.List (all) import Data.Char (isSpace)+import Data.Text (Text, splitOn)+import Data.Text.Encoding (decodeUtf8, encodeUtf8) input_bytestring :: Env -> IO ByteString@@ -44,7 +44,7 @@ media_type_params :: Env -> [(ByteString, ByteString)] media_type_params env | env.content_type.B.unpack.empty = []- | otherwise = + | otherwise = env .content_type .B.unpack@@ -69,41 +69,52 @@ params env = if env.query_string.B.unpack.all isSpace then []- else env.query_string.B.unpack.formDecode.map_both (u2b > B.pack)--inputs :: Env -> IO [(ByteString, ByteString)]-inputs env = do- _body <- env.input_bytestring- return - - env- .httpHeaders- .map_fst (B.unpack > upper > map (\x -> if x == '-' then '_' else x)) -- cgi env use all cap letters- .map_snd B.unpack- .(("REQUEST_METHOD", env.request_method.show) : ) -- for cgi request- .flip decodeInput (_body.s2l)- .fst- .concatMap to_headers- + else env.query_string.decodeUtf8.decode_params.map_both encodeUtf8 where- to_headers (k, input) = case input.inputFilename of- Nothing -> [(k.B.pack, input.inputValue.l2s)]- Just name -> - [ (k.B.pack, input.inputValue.l2s)- , ("hack2_input_file_name_" + k.B.pack, name.B.pack)- ]+ decode_params :: Text -> [(Text, Text)]+ decode_params x =+ x.splitOn "&".map decode_pair + decode_pair :: Text -> (Text, Text)+ decode_pair x =+ case x.splitOn "=" of+ [] -> ("", "")+ [x] -> (x, "")+ (x:y:_) -> (x,y)++-- inputs :: Env -> IO [(ByteString, ByteString)]+-- inputs env = do+-- _body <- env.input_bytestring+-- return -+-- env+-- .httpHeaders+-- .map_fst (B.unpack > upper > map (\x -> if x == '-' then '_' else x)) -- cgi env use all cap letters+-- .map_snd B.unpack+-- .(("REQUEST_METHOD", env.request_method.show) : ) -- for cgi request+-- .flip decodeInput (_body.s2l)+-- .fst+-- .concatMap to_headers+--+-- where+-- to_headers (k, input) = case input.inputFilename of+-- Nothing -> [(k.B.pack, input.inputValue.l2s)]+-- Just name ->+-- [ (k.B.pack, input.inputValue.l2s)+-- , ("hack2_input_file_name_" + k.B.pack, name.B.pack)+-- ]+ referer :: Env -> ByteString referer = httpHeaders > get _Referer > fromMaybe "/" -cookies :: Env -> [(ByteString, ByteString)]-cookies env = case env.httpHeaders.get _Cookie of- Nothing -> []- Just s -> s.B.unpack.readCookies .map_both B.pack+-- cookies :: Env -> [(ByteString, ByteString)]+-- cookies env = case env.httpHeaders.get _Cookie of+-- Nothing -> []+-- Just s -> s.B.unpack.readCookies .map_both B.pack fullpath :: Env -> ByteString-fullpath env = - if env.query_string.B.unpack.all isSpace - then env.path +fullpath env =+ if env.query_string.B.unpack.all isSpace+ then env.path else env.path + "?" + env.query_string set_http_header :: ByteString -> ByteString -> Env -> Env@@ -122,13 +133,13 @@ ] .B.concat where- port_string = - if (env.scheme.is "https" && env.port.is_not 443 || + port_string =+ if (env.scheme.is "https" && env.port.is_not 443 || env.scheme.is "http" && env.port.is_not 80 ) then ":" + env.server_port.show_bytestring else "" remote_host :: Env -> ByteString-remote_host env = +remote_host env = ( env.hackHeaders + env.httpHeaders ) .lookup "RemoteHost" .fromMaybe ""