on wai-eventsource/1.3.0.4 help sign in
typeable/wai/warp/test/RequestSpec.hs
31 lines 1.1 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
3module RequestSpec (main, spec) where
5import Data.Conduit
6import Data.Conduit.List
7import Network.Wai.Handler.Warp.Request
8import Network.Wai.Handler.Warp.Types
9import Test.Hspec
11main :: IO ()
12main = hspec spec
14spec :: Spec
15spec = describe "takeHeaders" $ do
16 it "takes until blank" $
17 blankSafe >>= (`shouldBe` ["foo", "bar", "baz"])
18 it "ignored leading whitespace in bodies" $
19 whiteSafe >>= (`shouldBe` ["foo", "bar", "baz"])
20 it "throws OverLargeHeader when too many" $
21 tooMany `shouldThrow` overLargeHeader
22 it "throws OverLargeHeader when too large" $
23 tooLarge `shouldThrow` overLargeHeader
24 where
25 blankSafe = runResourceT $ (sourceList ["f", "oo\n", "bar\nbaz\n\r\n"]) $$ takeHeaders
26 whiteSafe = runResourceT $ (sourceList ["foo\r\nbar\r\nbaz\r\n\r\n hi there"]) $$ takeHeaders
27 tooMany = runResourceT $ (sourceList $ repeat "f\n") $$ takeHeaders
28 tooLarge = runResourceT $ (sourceList $ repeat "f") $$ takeHeaders
30overLargeHeader :: Selector InvalidRequest
31overLargeHeader e = e == OverLargeHeader