[Haskell-cafe] Enumeratee that generates data

tsuraan tsuraan at gmail.com
Sun Sep 4 18:03:34 CEST 2011

I'm trying to write a program whose network behaviour is analogous to
a web proxy.  A client connects to my server and gives me some data,
my server connects to an upstream server and gives data to it, my
server gets data from upstream, and gives data to the client.  I'd
like to write this using the enumerator library, since it seems like
it should be possible to do that cleanly.  Now, the guts of an echo
server are pretty easy:

runIteratee $ enumSocket cs sock $$ iterSocket sock

That's just plain pretty.  You can even put interesting data
tranformations (Enumeratees) in there to make it behave a bit
differently.  What I'd like to do is have an Enumeratee that connects
to the upstream server, forwards the request, and then uses one of the
Data.Enumerator.List functions to generate a response that is the
response from the upstream server.  It doesn't look like this is
possible though, since Enumeratees are pretty much one output per

Is my basic model broken here?  It's occurred to me that what I
actually want to do is tie the enumSocket clientSock to an iterSocket
upstreamSock, do the reverse, and then do two runIteratee calls (one
in a forkIO, I guess?).  That seems uglier, I'm not sure if there
would be complications in making sure both Iteratees stop running
correctly.  Is that the right way to do, or am I just missing some
capability that Enumeratees have?

More information about the Haskell-Cafe mailing list