~ubuntu-branches/ubuntu/saucy/haskell-wai-extra/saucy

« back to all changes in this revision

Viewing changes to Network/Wai/Parse.hs

  • Committer: Package Import Robot
  • Author(s): Clint Adams
  • Date: 2012-05-15 00:58:38 UTC
  • mfrom: (2.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120515005838-zicbz35rrqbn305y
Tags: 1.2.0.4-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
182
182
 
183
183
sinkRequestBody :: BackEnd y
184
184
                -> RequestBodyType
185
 
                -> C.Sink S.ByteString IO ([Param], [File y])
 
185
                -> C.Sink S.ByteString (C.ResourceT IO) ([Param], [File y])
186
186
sinkRequestBody s r = fmap partitionEithers $ conduitRequestBody s r C.=$ CL.consume
187
187
 
188
188
conduitRequestBody :: BackEnd y
189
189
                   -> RequestBodyType
190
 
                   -> C.Conduit S.ByteString IO (Either Param (File y))
 
190
                   -> C.Conduit S.ByteString (C.ResourceT IO) (Either Param (File y))
191
191
conduitRequestBody _ UrlEncoded = C.sequenceSink () $ \() -> do -- url-encoded
192
192
    -- NOTE: in general, url-encoded data will be in a single chunk.
193
193
    -- Therefore, I'm optimizing for the usual case by sticking with
197
197
conduitRequestBody backend (Multipart bound) =
198
198
    parsePieces backend $ S8.pack "--" `S.append` bound
199
199
 
200
 
takeLine :: C.Sink S.ByteString IO (Maybe S.ByteString)
 
200
takeLine :: C.Sink S.ByteString (C.ResourceT IO) (Maybe S.ByteString)
201
201
takeLine =
202
202
    C.sinkState id push close'
203
203
  where
210
210
                    let lo = if S.length y > 1 then Just (S.drop 1 y) else Nothing
211
211
                    return $ C.StateDone lo $ Just $ killCR x
212
212
 
213
 
takeLines :: C.Sink S.ByteString IO [S.ByteString]
 
213
takeLines :: C.Sink S.ByteString (C.ResourceT IO) [S.ByteString]
214
214
takeLines = do
215
215
    res <- takeLine
216
216
    case res of
222
222
                return $ l : ls
223
223
 
224
224
parsePieces :: BackEnd y -> S.ByteString
225
 
            -> C.Conduit S.ByteString IO (Either Param (File y))
 
225
            -> C.Conduit S.ByteString (C.ResourceT IO) (Either Param (File y))
226
226
parsePieces sink bound = C.sequenceSink True (parsePiecesSink sink bound)
227
227
 
228
228
parsePiecesSink :: BackEnd y
229
229
                -> S.ByteString
230
 
                -> C.SequencedSink Bool S.ByteString IO (Either Param (File y))
 
230
                -> C.SequencedSink Bool S.ByteString (C.ResourceT IO) (Either Param (File y))
231
231
parsePiecesSink _ _ False = return C.Stop
232
232
parsePiecesSink BackEnd{initialize=initialize',append=append',close=close'}
233
233
                bound True = do
299
299
sinkTillBound :: S.ByteString
300
300
              -> (x -> S.ByteString -> IO x)
301
301
              -> x
302
 
              -> C.Sink S.ByteString IO (x, Bool)
 
302
              -> C.Sink S.ByteString (C.ResourceT IO) (x, Bool)
303
303
sinkTillBound bound iter seed0 = C.sinkState
304
304
    (id, seed0)
305
305
    push