on wai-handler-devel/1.3.0.1 help sign in
74 lines 2.1 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2import Network.Wai
3import Network.Wai.Handler.Warp (defaultSettings)
4import Network.Wai.Handler.WarpTLS
5import Network.HTTP.Types (status200)
6import Blaze.ByteString.Builder (copyByteString)
7import Data.Monoid
8import qualified Data.Conduit as C
9import qualified Data.Conduit.List as CL
11main = do
12 putStrLn "https://localhost:3000/"
13 runTLS (TLSSettings "certificate.pem" "key.pem") defaultSettings app
15app req = return $
16 case rawPathInfo req of
17 "/builder/withlen" -> builderWithLen
18 "/builder/nolen" -> builderNoLen
19 "/file/withlen" -> fileWithLen
20 "/file/nolen" -> fileNoLen
21 "/source/withlen" -> sourceWithLen
22 "/source/nolen" -> sourceNoLen
23 x -> index x
25builderWithLen = ResponseBuilder
26 status200
27 [ ("Content-Type", "text/plain")
28 , ("Content-Length", "4")
29 ]
30 $ copyByteString "PONG"
32builderNoLen = ResponseBuilder
33 status200
34 [ ("Content-Type", "text/plain")
35 ]
36 $ copyByteString "PONG"
38sourceWithLen = ResponseSource
39 status200
40 [ ("Content-Type", "text/plain")
41 , ("Content-Length", "4")
42 ]
43 $ CL.sourceList [C.Chunk $ copyByteString "PONG"]
45sourceNoLen = ResponseSource
46 status200
47 [ ("Content-Type", "text/plain")
48 ]
49 $ CL.sourceList [C.Chunk $ copyByteString "PONG"]
51fileWithLen = ResponseFile
52 status200
53 [ ("Content-Type", "text/plain")
54 , ("Content-Length", "4")
55 ]
56 "pong.txt"
57 Nothing
59fileNoLen = ResponseFile
60 status200
61 [ ("Content-Type", "text/plain")
62 ]
63 "pong.txt"
64 Nothing
66index p = ResponseBuilder status200 [("Content-Type", "text/html")] $ mconcat $ map copyByteString
67 [ "<p><a href='/builder/withlen'>builder withlen</a></p>\n"
68 , "<p><a href='/builder/nolen'>builder nolen</a></p>\n"
69 , "<p><a href='/file/withlen'>file withlen</a></p>\n"
70 , "<p><a href='/file/nolen'>file nolen</a></p>\n"
71 , "<p><a href='/source/withlen'>source withlen</a></p>\n"
72 , "<p><a href='/source/nolen'>source nolen</a></p>\n"
73 , p
74 ]