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

admin

Administrator
Staff member
The module <a href="http://hackage.haskell.org/packages/archive/HTTP/4000.1.1/doc/html/Network-HTTP.html" rel="noreferrer">
Code:
Network.HTTP
</a>
exposes the functions
Code:
receiveHTTP
and
Code:
respondHTTP
which I'd like to use for a very basic web server. I wrote a stub that just waits for clients:

Code:
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Network.HTTP
import Network
import Control.Monad

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

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

I found <a href="http://lstephen.wordpress.com/2008/02/14/a-simple-haskell-web-server/" rel="noreferrer">an example</a> with Google, but it is from 2008 and does not work anymore. And I was not able to port it.

Any ideas?