forked from softmechanics/warp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpong.hs
67 lines (58 loc) · 1.83 KB
/
pong.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{-# LANGUAGE OverloadedStrings #-}
import Network.Wai
import Network.Wai.Handler.Warp
import Blaze.ByteString.Builder (copyByteString)
import Data.Monoid
import Data.Enumerator (run_, enumList, ($$))
main = run 3000 app
app req = return $
case pathInfo req of
"/builder/withlen" -> builderWithLen
"/builder/nolen" -> builderNoLen
"/enum/withlen" -> enumWithLen
"/enum/nolen" -> enumNoLen
"/file/withlen" -> fileWithLen
"/file/nolen" -> fileNoLen
_ -> index $ pathInfo req
builderWithLen = ResponseBuilder
status200
[ ("Content-Type", "text/plain")
, ("Content-Length", "4")
]
$ copyByteString "PONG"
builderNoLen = ResponseBuilder
status200
[ ("Content-Type", "text/plain")
]
$ copyByteString "PONG"
fileWithLen = ResponseFile
status200
[ ("Content-Type", "text/plain")
, ("Content-Length", "4")
]
"pong.txt"
fileNoLen = ResponseFile
status200
[ ("Content-Type", "text/plain")
]
"pong.txt"
enumWithLen = ResponseEnumerator $ \f ->
run_ $ (enumList 1 $ map copyByteString ["P", "O", "NG"]) $$ f
status200
[ ("Content-Type", "text/plain")
, ("Content-Length", "4")
]
enumNoLen = ResponseEnumerator $ \f ->
run_ $ (enumList 1 $ map copyByteString ["P", "O", "NG"]) $$ f
status200
[ ("Content-Type", "text/plain")
]
index p = ResponseBuilder status200 [("Content-Type", "text/html")] $ mconcat $ map copyByteString
[ "<p><a href='/builder/withlen'>builder withlen</a></p>\n"
, "<p><a href='/builder/nolen'>builder nolen</a></p>\n"
, "<p><a href='/enum/withlen'>enum withlen</a></p>\n"
, "<p><a href='/enum/nolen'>enum nolen</a></p>\n"
, "<p><a href='/file/withlen'>file withlen</a></p>\n"
, "<p><a href='/file/nolen'>file nolen</a></p>\n"
, p
]