packages feed

http-monad-0.0.1: test/Infinity.hs

{- |
It's important that the content is generated by functions (with dummy arguments)
which are also inlined.
Otherwise GHC buffers their content and runs into heap exhaustion.
-}
module Main where

import qualified Network.Shed.Httpd as HTTP


{-# INLINE items #-}
items :: HTTP.Request -> [String]
items (HTTP.Request{}) =
   map show $ iterate ((1::Integer)+) 0

{-# INLINE text #-}
text :: HTTP.Request -> String
text r =
   concat $
   "<html>" :
   "<body>" :
   "<ul>" :
   map (\s -> "<li> "++s++" </li>") (items r) ++
   "</ul>" :
   "</body>" :
   "</html>" :
   []

{-# INLINE response #-}
response :: HTTP.Request -> HTTP.Response
response r =
   HTTP.Response 200
      (("Content-Type", "text/html") :
       [])
      (text r)


mainText :: IO ()
mainText =
   HTTP.initServerLazy 1000 8080
      (const (return (HTTP.Response 200
         (("Content-Type", "text/plain") :
          [])
         (cycle "bla"))))
    >> return ()

main :: IO ()
main =
   HTTP.initServerLazy 1000 8080 (return . response)
    >> return ()