Skip to content
Browse files

Add a test for escapeHttp

  • Loading branch information...
1 parent f13d2e1 commit eec6d3e5c85c8bcd3a21e1c22d2f502749e24c73 @jaspervdj jaspervdj committed Nov 9, 2011
Showing with 28 additions and 0 deletions.
  1. +28 −0 test/suite/Snap/Internal/Http/Server/Tests.hs
View
28 test/suite/Snap/Internal/Http/Server/Tests.hs
@@ -27,6 +27,8 @@ import Data.ByteString (ByteString)
import Data.ByteString.Internal (c2w)
import qualified Data.CaseInsensitive as CI
import Data.Char
+import qualified Data.Enumerator as E
+import qualified Data.Enumerator.List as EL
import Data.Int
import Data.IORef
import Data.List (foldl', sort)
@@ -75,6 +77,7 @@ tests = [ testHttpRequest1
, testHttp2
, testHttp100
, test411
+ , testEscapeHttp
, testExpectGarbage
, testPartialParse
, testMethodParsing
@@ -847,6 +850,31 @@ test411 = testCase "server/expect411" $ do
assertBool "411 Length Required" ok
+testEscapeHttp :: Test
+testEscapeHttp = testCase "server/escapeHttp" $ do
+ ref <- newIORef ""
+ let (iter,onSendFile) = mkIter ref
+
+ runHTTP 60
+ Nothing
+ Nothing
+ escapeServer
+ "localhost"
+ (SessionInfo "127.0.0.1" 80 "127.0.0.1" 58384 False)
+ (enumBS sampleRequest)
+ iter
+ onSendFile
+ (const $ return ())
+
+ s <- readIORef ref
+
+ assertEqual "escapeHttp" "0123456789" s
+ where
+ -- Escape HTTP traffic. Read one ByteString and send it back.
+ escapeServer = runSnap $ escapeHttp $ \_ sendIter -> do
+ Just bs <- EL.head
+ liftIO $ E.run_ $ E.enumList 1 [bs] $$ sendIter
+
testExpectGarbage :: Test
testExpectGarbage = testCase "server/expectGarbage" $ do

0 comments on commit eec6d3e

Please sign in to comment.
Something went wrong with that request. Please try again.