@@ -1,11 +1,67 @@
11{-# LANGUAGE OverloadedStrings #-}
22import Network.Wai
33import Network.Wai.Handler.Warp
4−import Blaze.ByteString.Builder (fromByteString)
4+import Blaze.ByteString.Builder (copyByteString)
5+import Data.Monoid
6+import Data.Enumerator (run_, enumList, ($$))
57
6−main = run 3000 $ const $ return $ ResponseBuilder
8+main = run 3000 app
9+
10+app req = return $
11+ case pathInfo req of
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
19+
20+builderWithLen = ResponseBuilder
721 status200
822 [ ("Content-Type", "text/plain")
923 , ("Content-Length", "4")
1024 ]
11− $ fromByteString "PONG"
25+ $ copyByteString "PONG"
26+
27+builderNoLen = ResponseBuilder
28+ status200
29+ [ ("Content-Type", "text/plain")
30+ ]
31+ $ copyByteString "PONG"
32+
33+fileWithLen = ResponseFile
34+ status200
35+ [ ("Content-Type", "text/plain")
36+ , ("Content-Length", "4")
37+ ]
38+ "pong.txt"
39+
40+fileNoLen = ResponseFile
41+ status200
42+ [ ("Content-Type", "text/plain")
43+ ]
44+ "pong.txt"
45+
46+enumWithLen = ResponseEnumerator $ \f ->
47+ run_ $ (enumList 1 $ map copyByteString ["P", "O", "NG"]) $$ f
48+ status200
49+ [ ("Content-Type", "text/plain")
50+ , ("Content-Length", "4")
51+ ]
52+
53+enumNoLen = ResponseEnumerator $ \f ->
54+ run_ $ (enumList 1 $ map copyByteString ["P", "O", "NG"]) $$ f
55+ status200
56+ [ ("Content-Type", "text/plain")
57+ ]
58+
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"
66+ , p
67+ ]