web-encodings 0.2.6.2 → 0.3.0
raw patch · 2 files changed
+2/−85 lines, 2 filesdep −wai
Dependencies removed: wai
Files
- Web/Encodings.hs +1/−83
- web-encodings.cabal +1/−2
Web/Encodings.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE OverloadedStrings #-} --------------------------------------------------------- -- | -- Module : Web.Encodings@@ -45,7 +46,6 @@ -- * Date/time encoding , formatW3 -- * WAI-specific decodings- , parseRequestBody , Sink (..) , lbsSink , tempFileSink@@ -72,7 +72,6 @@ import qualified Data.ByteString.Lazy as BL import Data.Maybe (catMaybes) import Data.Either (partitionEithers)-import Network.Wai import System.Directory (getTemporaryDirectory, removeFile) import System.IO import Control.Monad (foldM)@@ -475,41 +474,6 @@ , sinkFinalize = \fp -> removeFile fp } --- | This function works just like 'parsePost', which two important distinctions:------ * It runs on a 'Source', which is the datatype used by the WAI for feeding a--- request body.------ * It allows you to specify a 'Sink' for receiving each individual file--- parameter, so that you can avoid allocating large amounts of memory if--- desired.------ Remember that it is your obligation to call 'sinkFinalize' on the returned--- values.-parseRequestBody :: Sink x y- -> Request- -> IO ([(BL.ByteString, BL.ByteString)],- [(BS.ByteString, FileInfo BS.ByteString y)])-parseRequestBody sink req = do- let ctype = do- {- NOTE: Ignoring length, WAI must handle it- clen' <- lookup ReqContentLength $ requestHeaders req- clen'' <- readMay $ B8.unpack clen'- -}- ctype' <- lookup ReqContentType $ requestHeaders req- if B8.pack urlenc `BS.isPrefixOf` ctype'- then Just Nothing- else if B8.pack formBound `BS.isPrefixOf` ctype'- then Just $ Just (BS.drop (length formBound) ctype')- else Nothing- case ctype of- Nothing -> return ([], [])- Just Nothing -> do- lbs <- sourceToLbsStrict $ requestBody req- return (decodeUrlPairs lbs, [])- Just (Just bound) ->- parsePieces sink (PSBegin id) bound BS.empty (requestBody req) id id- type PieceReturn sink = Either (BL.ByteString, BL.ByteString)@@ -585,43 +549,6 @@ type Param = (BL.ByteString, BL.ByteString) type File y = (BS.ByteString, FileInfo BS.ByteString y) -parsePieces :: Sink x y- -> ParseState x- -> BS.ByteString- -> BS.ByteString- -> Source- -> ([Param] -> [Param])- -> ([File y] -> [File y])- -> IO ([Param], [File y])-parsePieces sink pstate boundary prev (Source source) frontp frontf = do- res <- source- case res of- Nothing -> do- (pstate', prev', frontp', frontf') <- go prev- if BS.null prev' || prev == prev' -- second clause ensures termination- then return (frontp' [], frontf' [])- else parsePieces sink pstate' boundary prev' (Source $ return Nothing) frontp' frontf'- Just (bs', source') -> do- let bs = BS.append prev bs'- (pstate', prev', frontp', frontf') <- go bs- parsePieces sink pstate' boundary prev' source' frontp' frontf'- where- go bs =- case hasBound boundary bs of- NoBound -> do- pstate' <- parsePiece' sink pstate bs- return (pstate', BS.empty, frontp, frontf)- MaybeBound -> return (pstate, bs, frontp, frontf)- HasBound before after -> do- pstate' <- parsePiece' sink pstate before- es <- extractState sink pstate'- let (frontp', frontf') =- case es of- Nothing -> (frontp, frontf)- Just (Left p) -> (frontp . (:) p, frontf)- Just (Right f) -> (frontp, frontf . (:) f)- return (PSBegin id, after, frontp', frontf')- extractState :: Sink x y -> ParseState x -> IO (Maybe (PieceReturn y))@@ -669,12 +596,3 @@ notEmpty (x, y) | BS.null y = Nothing | otherwise = Just (x, y)--sourceToLbsStrict :: Source -> IO BL.ByteString-sourceToLbsStrict source0 = go source0 id- where- go (Source source) front = do- res <- source- case res of- Nothing -> return $ BL.fromChunks $ front []- Just (bs, source') -> go source' $ front . (:) bs
web-encodings.cabal view
@@ -1,5 +1,5 @@ name: web-encodings-version: 0.2.6.2+version: 0.3.0 license: BSD3 license-file: LICENSE author: Michael Snoyman <michael@snoyman.com>@@ -23,7 +23,6 @@ bytestring >= 0.9.1.4 && < 0.10, text >= 0.5 && < 0.8, failure >= 0.0.0 && < 0.2,- wai >= 0.0.0 && < 0.2, directory >= 1 && < 1.1 exposed-modules: Web.Encodings Web.Encodings.MimeHeader,