on wai-handler-fastcgi/1.2.0.2 help sign in
72 lines 2.0 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2import Network.Wai
3import Network.Wai.Handler.Warp
4import Network.HTTP.Types (status200)
5import Blaze.ByteString.Builder (copyByteString)
6import Data.Monoid
7import qualified Data.Conduit as C
8import qualified Data.Conduit.List as CL
10main = run 3000 app
12app req = return $
13 case rawPathInfo req of
14 "/builder/withlen" -> builderWithLen
15 "/builder/nolen" -> builderNoLen
16 "/file/withlen" -> fileWithLen
17 "/file/nolen" -> fileNoLen
18 "/source/withlen" -> sourceWithLen
19 "/source/nolen" -> sourceNoLen
20 "/notfound" -> ResponseFile status200 [] "notfound" Nothing
21 x -> index x
23builderWithLen = ResponseBuilder
24 status200
25 [ ("Content-Type", "text/plain")
26 , ("Content-Length", "4")
27 ]
28 $ copyByteString "PONG"
30builderNoLen = ResponseBuilder
31 status200
32 [ ("Content-Type", "text/plain")
33 ]
34 $ copyByteString "PONG"
36sourceWithLen = ResponseSource
37 status200
38 [ ("Content-Type", "text/plain")
39 , ("Content-Length", "4")
40 ]
41 $ CL.sourceList [C.Chunk $ copyByteString "PONG"]
43sourceNoLen = ResponseSource
44 status200
45 [ ("Content-Type", "text/plain")
46 ]
47 $ CL.sourceList [C.Chunk $ copyByteString "PONG"]
49fileWithLen = ResponseFile
50 status200
51 [ ("Content-Type", "text/plain")
52 , ("Content-Length", "4")
53 ]
54 "pong.txt"
55 Nothing
57fileNoLen = ResponseFile
58 status200
59 [ ("Content-Type", "text/plain")
60 ]
61 "pong.txt"
62 Nothing
64index p = ResponseBuilder status200 [("Content-Type", "text/html")] $ mconcat $ map copyByteString
65 [ "<p><a href='/builder/withlen'>builder withlen</a></p>\n"
66 , "<p><a href='/builder/nolen'>builder nolen</a></p>\n"
67 , "<p><a href='/file/withlen'>file withlen</a></p>\n"
68 , "<p><a href='/file/nolen'>file nolen</a></p>\n"
69 , "<p><a href='/source/withlen'>source withlen</a></p>\n"
70 , "<p><a href='/source/nolen'>source nolen</a></p>\n"
71 , p
72 ]