on master help sign in
Removed web-encodings dependency
commitc10552f80b704a89646f840af5d1a602156e1d9e authorMichael Snoyman <michael@snoyman.com> dateThu 13 May 2010, 23:12 (16 years ago) parentfa13086
4 files changed+23−12
Network/Wai/Handler/SimpleServer.hs+8−4 Network/Wai/Middleware/CleanPath.hs+4−4 Network/Wai/Middleware/Jsonp.hs+11−3 wai-extra.cabal−1
Network/Wai/Handler/SimpleServer.hs+8−4
@@ -34,8 +34,6 @@ import Data.Maybe (isJust, fromJust, fromMaybe)
3434
3535import Data.Typeable (Typeable)
3636
37−import qualified Web.Encodings.StringLike as SL
38−
3937import Network.Socket.SendFile
4038import Control.Arrow (first)
4139
@@ -136,7 +134,7 @@ parseRequest port lines' handle remoteHost' = do
136134parseFirst :: ByteString
137135 -> IO (ByteString, ByteString, ByteString, HttpVersion)
138136parseFirst s = do
139− let pieces = SL.split ' ' s
137+ let pieces = B.words s
140138 (method, query, http') <-
141139 case pieces of
142140 [x, y, z] -> return (x, y, z)
@@ -173,4 +171,10 @@ sendResponse httpversion h res = do
173171parseHeaderNoAttr :: ByteString -> (ByteString, ByteString)
174172parseHeaderNoAttr s =
175173 let (k, rest) = B.span (/= ':') s
176− in (k, SL.dropPrefix' (B.pack ": ") rest)
174+ rest' = if not (B.null rest) &&
175+ B.head rest == ':' &&
176+ not (B.null $ B.tail rest) &&
177+ B.head (B.tail rest) == ' '
178+ then B.drop 2 rest
179+ else rest
180+ in (k, rest')
Network/Wai/Middleware/CleanPath.hs+4−4
@@ -1,11 +1,11 @@
11module Network.Wai.Middleware.CleanPath (cleanPath, splitPath) where
22
33import Network.Wai
4−import Web.Encodings
54import qualified Data.ByteString.Char8 as B
5+import Network.URI (unEscapeString)
66
77-- | Performs redirects as per 'splitPath'.
8−cleanPath :: ([B.ByteString] -> Request -> IO Response)
8+cleanPath :: ([String] -> Request -> IO Response)
99 -> Request
1010 -> IO Response
1111cleanPath app env =
@@ -32,11 +32,11 @@ emptyEnum = Enumerator $ \_ -> return . Right
3232-- last slash.
3333--
3434-- * There are any doubled slashes.
35−splitPath :: B.ByteString -> Either B.ByteString [B.ByteString]
35+splitPath :: B.ByteString -> Either B.ByteString [String]
3636splitPath s =
3737 let corrected = B.pack $ ats $ rds $ B.unpack s
3838 in if corrected == s
39− then Right $ map decodeUrl
39+ then Right $ map (unEscapeString . B.unpack)
4040 $ filter (not . B.null)
4141 $ B.split '/' s
4242 else Left corrected
Network/Wai/Middleware/Jsonp.hs+11−3
@@ -15,10 +15,19 @@ module Network.Wai.Middleware.Jsonp (jsonp) where
1515
1616import Network.Wai
1717import Network.Wai.Enumerator (fromEitherFile)
18−import Web.Encodings (decodeUrlPairs)
1918import qualified Data.ByteString.Char8 as B8
2019import Data.Maybe (fromMaybe)
2120
21+takeCallback :: B8.ByteString -> Maybe B8.ByteString
22+takeCallback bs | B8.null bs = Nothing
23+takeCallback bs =
24+ let (x, y) = B8.break (== '=') bs
25+ (y', z) = B8.break (== '&') $ B8.drop 1 y
26+ in if x == B8.pack "callback"
27+ then Just y'
28+ else takeCallback $ B8.drop 1 z
29+
30+
2231-- | Wrap json responses in a jsonp callback.
2332--
2433-- Basically, if the user requested a \"text\/javascript\" and supplied a
@@ -29,11 +38,10 @@ import Data.Maybe (fromMaybe)
2938jsonp :: Middleware
3039jsonp app env = do
3140 let accept = fromMaybe B8.empty $ lookup Accept $ requestHeaders env
32− let gets = decodeUrlPairs $ queryString env
3341 let callback :: Maybe B8.ByteString
3442 callback =
3543 if B8.pack "text/javascript" `B8.isInfixOf` accept
36− then lookup (B8.pack "callback") gets
44+ then takeCallback $ queryString env
3745 else Nothing
3846 let env' =
3947 case callback of
wai-extra.cabal−1
@@ -16,7 +16,6 @@ Library
1616 Build-Depends: base >= 3 && < 5,
1717 bytestring >= 0.9 && < 0.10,
1818 wai >= 0.0.0 && < 0.1,
19− web-encodings >= 0.2.6 && < 0.3,
2019 old-locale >= 1.0 && < 1.1,
2120 time >= 1.1.4 && < 1.2,
2221 zlib >= 0.5.2.0 && < 0.6,