Skip to content

Instantly share code, notes, and snippets.

@kowey
Created March 12, 2012 18:44
Show Gist options
  • Save kowey/2023894 to your computer and use it in GitHub Desktop.
Save kowey/2023894 to your computer and use it in GitHub Desktop.
{-# LANGUAGE OverloadedStrings #-}
import Control.Exception
import Control.Monad ( liftM, ap )
import Control.Monad.IO.Class
import Data.Conduit
import Data.Conduit.Lazy
import Data.IORef
import Network.HTTP.Types (statusOK, status400, Header, Ascii)
import Network.Wai
import Network.Wai.Handler.Warp -- (run)
import System.IO
import qualified Data.ByteString.Lazy as B
import qualified Network.Wai.Middleware.RequestLogger as W
main = do
hPutStrLn stderr $ "Listening on port " ++ show (settingsPort settings)
runSettings settings (W.logStdout application)
where
settings = defaultSettings { settingsHost = "127.0.0.1" -- force IPv4 usage
, settingsPort = 4000
}
application :: Application
application req = liftIO $ do
bss <- runResourceT . lazyConsume . requestBody $ req
B.putStrLn (B.fromChunks bss)
return $ responseLBS statusOK [("Content-type","text/plain")] $ B.fromChunks bss
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment