--- @limit@ may be less than or equal to zero. In this case, the
--- default limitation value ('cnfMaxEntityLength') is used. See
--- 'defaultLimit'.
---
--- Note that 'inputChunkLBS' is more efficient than 'inputChunk' so you
--- should use it whenever possible.
-inputChunk ∷ Int → Resource Lazy.ByteString
-inputChunk limit
- = do driftTo GettingBody
- itr ← getInteraction
- chunk ← if reqMustHaveBody $ fromJust $ itrRequest itr then
- askForInput itr
- else
- do driftTo DecidingHeader
- return (∅)
- return chunk
- where
- askForInput ∷ Interaction → Resource Lazy.ByteString
- askForInput (Interaction {..})
- = do let confLimit = cnfMaxEntityLength itrConfig
- actualLimit = if limit < 0 then
- confLimit
- else
- limit
- when (actualLimit ≤ 0)
- $ fail ("inputChunkLBS: limit must be positive: " ++ show actualLimit)
- -- Reader にリクエスト
- liftIO $ atomically
- $ writeTVar itrReqBodyWanted actualLimit
- -- 應答を待つ。トランザクションを分けなければ當然デッドロック。
- chunk ← liftIO $ atomically
- $ do chunkLen ← readTVar itrReceivedBodyLen
- -- 要求された量に滿たなくて、まだ殘りがある
- -- なら再試行。
- when (chunkLen < actualLimit)
- $ do chunkIsOver ← readTVar itrReqChunkIsOver
- unless chunkIsOver
- $ retry
- -- 成功
- chunk ← seqToLBS <$> readTVar itrReceivedBody
- writeTVar itrReceivedBody (∅)
- writeTVar itrReceivedBodyLen 0
- return chunk
- when (Lazy.null chunk)
- $ driftTo DecidingHeader
- return chunk
-
--- | Computation of @'inputForm' limit@ attempts to read the request
--- body with 'input' and parse it as
--- @application\/x-www-form-urlencoded@ or @multipart\/form-data@. If
--- the request header \"Content-Type\" is neither of them, 'inputForm'
--- makes 'Resource' abort with status \"415 Unsupported Media
--- Type\". If the request has no \"Content-Type\", it aborts with
--- \"400 Bad Request\".
---
--- Field names in @multipart\/form-data@ will be precisely decoded in
--- accordance with RFC 2231. On the other hand,
--- @application\/x-www-form-urlencoded@ says nothing about the
--- encoding of field names, so they'll always be decoded in UTF-8.
-inputForm ∷ Int → Resource [(Text, FormData)]
-inputForm limit