~ubuntu-branches/ubuntu/utopic/haskell-wai-extra/utopic

« back to all changes in this revision

Viewing changes to test/sample.hs

  • Committer: Package Import Robot
  • Author(s): Joachim Breitner
  • Date: 2014-05-03 10:15:30 UTC
  • mfrom: (2.2.6 sid)
  • Revision ID: package-import@ubuntu.com-20140503101530-9e99lxx6x6xd2o9o
Tags: 2.1.1-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import Data.ByteString.Char8 (unpack, pack)
 
1
{-# LANGUAGE OverloadedStrings #-}
 
2
 
 
3
import Data.ByteString.Char8 (pack)
2
4
import Data.ByteString.Lazy (fromChunks)
 
5
import Data.Text ()
 
6
import Network.HTTP.Types
3
7
import Network.Wai
4
 
import Network.Wai.Enumerator
5
8
import Network.Wai.Middleware.Gzip
6
9
import Network.Wai.Middleware.Jsonp
7
 
import Network.Wai.Middleware.CleanPath
8
 
import Network.Wai.Handler.SimpleServer
 
10
import Network.Wai.Handler.Warp
9
11
 
10
 
app :: [String] -> Application
11
 
app [] _ = return $ Response Status200 [] $ Right $ fromLBS
12
 
                  $ fromChunks $ flip map [1..10000] $ \i -> pack $
13
 
                concat
 
12
app :: Application
 
13
app request = return $ case pathInfo request of
 
14
    [] -> responseLBS status200 []
 
15
            $ fromChunks $ flip map [1..10000] $ \i -> pack $ concat
14
16
                    [ "<p>Just this same paragraph again. "
15
 
                    , show i
 
17
                    , show (i :: Int)
16
18
                    , "</p>"
17
19
                    ]
18
 
app ["test.html"] _ = return $ Response Status200 [] $ Left "test.html"
19
 
app ["json"] _ =return $ Response Status200
20
 
                         [(ContentType, pack "application/json")]
21
 
                       $ Left "json"
22
 
app _ _ = return $ Response Status404 [] $ Left "../LICENSE"
 
20
    ["test.html"] -> ResponseFile status200 [] "test.html" Nothing
 
21
    ["json"]      -> ResponseFile status200 [(hContentType, "application/json")]
 
22
                                               "json" Nothing
 
23
    _             -> ResponseFile status404 [] "../LICENSE" Nothing
23
24
 
24
25
main :: IO ()
25
 
main = run 3000 $ jsonp $ gzip $ cleanPath app
 
26
main = run 3000 $ gzip def $ jsonp app