wai 3.0.0.2 → 3.0.1
raw patch · 3 files changed
+27/−1 lines, 3 files
Files
- Network/Wai.hs +15/−0
- test/Network/WaiSpec.hs +11/−0
- wai.cabal +1/−1
Network/Wai.hs view
@@ -59,6 +59,7 @@ , requestBodyLength , requestHeaderHost , requestHeaderRange+ , strictRequestBody , lazyRequestBody -- * Response , Response@@ -277,6 +278,20 @@ , requestHeaderHost = Nothing , requestHeaderRange = Nothing }++-- | Get the request body as a lazy ByteString. However, do /not/ use any lazy+-- I\/O, instead reading the entire body into memory strictly.+--+-- Since 3.0.1+strictRequestBody :: Request -> IO L.ByteString+strictRequestBody req =+ loop id+ where+ loop front = do+ bs <- requestBody req+ if B.null bs+ then return $ front LI.Empty+ else loop (front . LI.Chunk bs) -- | Get the request body as a lazy ByteString. This uses lazy I\/O under the -- surface, and therefore all typical warnings regarding lazy I/O apply.
test/Network/WaiSpec.hs view
@@ -71,3 +71,14 @@ } _ <- lazyRequestBody req return ()+ describe "strictRequestBody" $ do+ prop "works" $ \chunks -> do+ ref <- newIORef $ map S.pack $ filter (not . null) chunks+ let req = Request+ { requestBody = atomicModifyIORef ref $ \bss ->+ case bss of+ [] -> ([], S.empty)+ x:y -> (y, x)+ }+ body <- strictRequestBody req+ body `shouldBe` L.fromChunks (map S.pack chunks)
wai.cabal view
@@ -1,5 +1,5 @@ Name: wai-Version: 3.0.0.2+Version: 3.0.1 Synopsis: Web Application Interface. Description: Provides a common protocol for communication between web applications and web servers. License: MIT