File: sample.hs

package info (click to toggle)
haskell-wai-extra 3.0.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 236 kB
  • ctags: 1
  • sloc: haskell: 2,177; makefile: 3
file content (26 lines) | stat: -rw-r--r-- 934 bytes parent folder | download | duplicates (5)
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
{-# LANGUAGE OverloadedStrings #-}

import Data.ByteString.Char8 (pack)
import Data.ByteString.Lazy (fromChunks)
import Data.Text ()
import Network.HTTP.Types
import Network.Wai
import Network.Wai.Middleware.Gzip
import Network.Wai.Middleware.Jsonp
import Network.Wai.Handler.Warp

app :: Application
app request = return $ case pathInfo request of
    [] -> responseLBS status200 []
            $ fromChunks $ flip map [1..10000] $ \i -> pack $ concat
                    [ "<p>Just this same paragraph again. "
                    , show (i :: Int)
                    , "</p>"
                    ]
    ["test.html"] -> ResponseFile status200 [] "test.html" Nothing
    ["json"]      -> ResponseFile status200 [(hContentType, "application/json")]
                                               "json" Nothing
    _             -> ResponseFile status404 [] "../LICENSE" Nothing

main :: IO ()
main = run 3000 $ gzip def $ jsonp app