on master help sign in
Hopefully solve a gzip and parse bug
commit8cd6f70cce2b3503308320cd4e9c08e128b2ca4e authorMichael <michael@snoyman.com> dateSun 27 Feb 2011, 08:22 (16 years ago) parent682389b
3 files changed+20−8
Network/Wai/Middleware/Gzip.hs+4−1 Network/Wai/Parse.hs+15−6 wai-extra.cabal+1−1
Network/Wai/Middleware/Gzip.hs+4−1
@@ -55,7 +55,10 @@ compressE re f =
5555 f' s hs =
5656 joinI $ compress $$ f s hs'
5757 where
58− hs' = ("Content-Encoding", "gzip") : hs
58+ -- Remove Content-Length header, since we will certainly have a
59+ -- different length after gzip compression.
60+ hs' = ("Content-Encoding", "gzip") : filter notLength hs
61+ notLength (x, _) = x /= "content-length"
5962
6063splitCommas :: String -> [String]
6164splitCommas [] = []
Network/Wai/Parse.hs+15−6
@@ -164,18 +164,27 @@ parseRequestBody sink req = do
164164 bs <- E.consume
165165 return (parseQueryString $ S.concat bs, [])
166166 Just (Just bound) -> -- multi-part
167− let bound' = S8.pack "--" `S.append` bound
168− in parsePieces sink bound'
167+ let bound'' = S8.pack "--" `S.append` bound
168+ in parsePieces sink bound''
169169 where
170170 urlenc = S8.pack "application/x-www-form-urlencoded"
171− formBound = S8.pack "multipart/form-data; boundary="
171+ formBound = S8.pack "multipart/form-data;"
172+ bound' = "boundary="
173+ boundary s =
174+ if "multipart/form-data;" `S.isPrefixOf` s
175+ then
176+ let s' = S.dropWhile (== 32) $ S.drop (S.length formBound) s
177+ in if bound' `S.isPrefixOf` s'
178+ then Just $ S.drop (S.length bound') s'
179+ else Nothing
180+ else Nothing
172181 ctype = do
173182 ctype' <- lookup "Content-Type" $ requestHeaders req
174183 if urlenc `S.isPrefixOf` ctype'
175184 then Just Nothing
176− else if formBound `S.isPrefixOf` ctype'
177− then Just $ Just $ S.drop (S.length formBound) ctype'
178− else Nothing
185+ else case boundary ctype' of
186+ Just x -> Just $ Just x
187+ Nothing -> Nothing
179188
180189takeLine :: Iteratee S.ByteString IO (Maybe S.ByteString)
181190takeLine = do
wai-extra.cabal+1−1
@@ -1,5 +1,5 @@
11Name: wai-extra
2−Version: 0.3.2
2+Version: 0.3.2.1
33Synopsis: Provides some basic WAI handlers and middleware.
44Description: The goal here is to provide common features without many dependencies.
55License: BSD3