@@ -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