on wai-eventsource/1.3.0.4 help sign in
77 lines 2.2 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2import Network.Wai
3import Network.Wai.Handler.Warp (defaultSettings, settingsPort)
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
10import Network.HTTP.ReverseProxy
11import Network.HTTP.Conduit
13main = do
14 putStrLn "https://localhost:3009/"
15 manager <- newManager def
16 runTLS (tlsSettings "config/tls-cert" "config/tls-key") defaultSettings { settingsPort = 3009 } app
18app req = return $
19 case rawPathInfo req of
20 "/builder/withlen" -> builderWithLen
21 "/builder/nolen" -> builderNoLen
22 "/file/withlen" -> fileWithLen
23 "/file/nolen" -> fileNoLen
24 "/source/withlen" -> sourceWithLen
25 "/source/nolen" -> sourceNoLen
26 x -> index x
28builderWithLen = ResponseBuilder
29 status200
30 [ ("Content-Type", "text/plain")
31 , ("Content-Length", "4")
32 ]
33 $ copyByteString "PONG"
35builderNoLen = ResponseBuilder
36 status200
37 [ ("Content-Type", "text/plain")
38 ]
39 $ copyByteString "PONG"
41sourceWithLen = ResponseSource
42 status200
43 [ ("Content-Type", "text/plain")
44 , ("Content-Length", "4")
45 ]
46 $ CL.sourceList [C.Chunk $ copyByteString "PONG"]
48sourceNoLen = ResponseSource
49 status200
50 [ ("Content-Type", "text/plain")
51 ]
52 $ CL.sourceList [C.Chunk $ copyByteString "PONG"]
54fileWithLen = ResponseFile
55 status200
56 [ ("Content-Type", "text/plain")
57 , ("Content-Length", "4")
58 ]
59 "pong.txt"
60 Nothing
62fileNoLen = ResponseFile
63 status200
64 [ ("Content-Type", "text/plain")
65 ]
66 "pong.txt"
67 Nothing
69index p = ResponseBuilder status200 [("Content-Type", "text/html")] $ mconcat $ map copyByteString
70 [ "<p><a href='/builder/withlen'>builder withlen</a></p>\n"
71 , "<p><a href='/builder/nolen'>builder nolen</a></p>\n"
72 , "<p><a href='/file/withlen'>file withlen</a></p>\n"
73 , "<p><a href='/file/nolen'>file nolen</a></p>\n"
74 , "<p><a href='/source/withlen'>source withlen</a></p>\n"
75 , "<p><a href='/source/nolen'>source nolen</a></p>\n"
76 , p
77 ]