This is a simple "echo" server written using `pipes-wai`:
{-# LANGUAGE OverloadedStrings #-}
import Blaze.ByteString.Builder (fromByteString)
import Pipes
import qualified Pipes.Prelude as Pipes
import Pipes.Wai
import Network.Wai.Handler.Warp
import Network.HTTP.Types (Status(..))
main = run 8000 $ \request onResponse -> do
let p = do
producerRequestBody request >-> Pipes.map (Chunk .
fromByteString)
yield Flush
onResponse (responseProducer (Status 200 "") [] p)
`producerRequestBody` turns the incoming client's request into a
`Producer`. Then you can do whatever you want with that `Producer`,
like read in its contents, discard it, or (in the above example) stream
it directly to the response.
If you give a more specific example of what you want to do, I can give a
more specific example.
On 06/28/2014 02:20 PM, Nicolas Trangez wrote:
On Sat, 2014-06-28 at 14:12 -0700, Gabriel Gonzalez wrote:
Have you tried the `pipes-wai` library?
I passed by it during my search, but its operations seem client-centric:
turning a `Request` into a `Producer ByteString m ()` (in order to
stream the data from that producer to some server?), or create a
`Response` out of a `Producer (Flush Builder) IO ()` (in order to stream
data from the producer to a client on some server?).
I could be missing something very obvious, but I don't think that's what
I need.
Thanks,
Nicolas
On Jun 28, 2014 1:52 PM, "Nicolas Trangez" <[email protected]> wrote:
All,
Has anyone ever written anything HTTP-server-like using Pipes? I looked
into Warp to check whether it could be integrated, but Warp seems to do
connection management, thread management, timeout handling, whatnot,
which is not what I need.
I'm looking for something simpler: given a `Producer ByteString m r` and
a `Consumer ByteString m r`, read a `Request` from the producer, then do
some handling, and render a `Response` to the consumer.
Are there any libraries I could look into, or is Warp easy to integrate
yet I'm failing to see how?
Thanks,
Nicolas
--
You received this message because you are subscribed to the Google Groups
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to [email protected].
To post to this group, send email to [email protected].
--
You received this message because you are subscribed to the Google Groups "Haskell
Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].