How to write a simple HTTP server in Haskell using Network.HTTP.receiveHTTP

The module Network.HTTP exposes the functions receiveHTTP and respondHTTP which I'd like to use for a very basic web server. I wrote a stub that just waits for clients:

{-# LANGUAGE OverloadedStrings #-}
module Main where

import Network.HTTP
import Network
import Control.Monad

main = withSocketsDo $ do
  socket <- listenOn $ PortNumber 8080
  forever $ do
    (handle, host, port) <- accept socket
    print (host, port)

Here accpet gives me a Handle, and now I can't figure out how to use a Handle with receiveHTTP.

I found an example with Google, but it is from 2008 and does not work anymore. And I was not able to port it.

Any ideas?

14
задан Soni Bergraj 27 May 2011 в 20:13
поделиться