@@ -1,11 +1,67 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2import Network.Wai
2import Network.Wai
3import Network.Wai.Handler.Warp
3import Network.Wai.Handler.Warp
4−import Blaze.ByteString.Builder (fromByteString)
4+import Blaze.ByteString.Builder (copyByteString)
6+import Data.Enumerator (run_, enumList, ($$))
12+ "/builder/withlen" -> builderWithLen
13+ "/builder/nolen" -> builderNoLen
14+ "/enum/withlen" -> enumWithLen
15+ "/enum/nolen" -> enumNoLen
16+ "/file/withlen" -> fileWithLen
17+ "/file/nolen" -> fileNoLen
18+ _ -> index $ pathInfo req
6−main = run 3000 $ const $ return $ ResponseBuilder
20+builderWithLen = ResponseBuilder
8 [ ("Content-Type", "text/plain")
22 [ ("Content-Type", "text/plain")
9 , ("Content-Length", "4")
23 , ("Content-Length", "4")
11− $ fromByteString "PONG"
25+ $ copyByteString "PONG"
27+builderNoLen = ResponseBuilder
29+ [ ("Content-Type", "text/plain")
31+ $ copyByteString "PONG"
33+fileWithLen = ResponseFile
35+ [ ("Content-Type", "text/plain")
36+ , ("Content-Length", "4")
40+fileNoLen = ResponseFile
42+ [ ("Content-Type", "text/plain")
46+enumWithLen = ResponseEnumerator $ \f ->
47+ run_ $ (enumList 1 $ map copyByteString ["P", "O", "NG"]) $$ f
49+ [ ("Content-Type", "text/plain")
50+ , ("Content-Length", "4")
53+enumNoLen = ResponseEnumerator $ \f ->
54+ run_ $ (enumList 1 $ map copyByteString ["P", "O", "NG"]) $$ f
56+ [ ("Content-Type", "text/plain")
59+index p = ResponseBuilder status200 [("Content-Type", "text/html")] $ mconcat $ map copyByteString
60+ [ "<p><a href='/builder/withlen'>builder withlen</a></p>\n"
61+ , "<p><a href='/builder/nolen'>builder nolen</a></p>\n"
62+ , "<p><a href='/enum/withlen'>enum withlen</a></p>\n"
63+ , "<p><a href='/enum/nolen'>enum nolen</a></p>\n"
64+ , "<p><a href='/file/withlen'>file withlen</a></p>\n"
65+ , "<p><a href='/file/nolen'>file nolen</a></p>\n"