I've updated that Gist to be compatible with WAI 3.0. The basic changes I made were:

1. Change the way Warp settings are applied (no longer use record syntax, but explicit set* functions).
2. conduit is no longer the standard streaming interface for WAI, so imported Network.Wai.Conduit and used helper functions from there.
3. The specific question you asked about: the semantics for how to do resource allocation in an application have changed. There were some holes in the previous approach that allowed async exceptions to leak in at the wrong time. Instead, WAI 3.0 uses a similar interface to most resource allocation functions in Haskell (like bracket or withFile). Specifically, this looks like:


    HCl.withResponse req2 man $ \res -> do
        let body = mapOutput (Chunk . fromByteString) $ HCC.bodyReaderSource $ HCl.responseBody res
            headers = filter safeResHeader $ HCl.responseHeaders res
        respond $ responseSource (HCl.responseStatus res) headers body

Some notes on this are available at:

* http://hackage.haskell.org/package/wai-3.0.2.3/docs/Network-Wai.html#t:Application
* http://www.yesodweb.com/book/web-application-interface#web-application-interface_resource_allocation
On Fri, Mar 6, 2015 at 10:58 AM Jos van den Oever <jos@vandenoever.info> wrote:
Hello all,

I'm studying the Yesod book by Michael Snoyman and I'm slowly coming to grips
with Haskell for the web.

My current goal is to write an http(s) proxy that does filtering and caching.
I've found a nice example by Snoyman on github:
  https://gist.github.com/snoyberg/8779671

This code does not compile with wai >= 3 because that does not have
responseSourceBracket any more. What is the best way to replace it?

---
Wai.responseSourceBracket (HCl.responseOpen req2 man) (HCl.responseClose) $
\res -> do
        let body = mapOutput (Chunk . fromByteString) $ HCC.bodyReaderSource $
HCl.responseBody res
                headers = filter safeResHeader $ HCl.responseHeaders res
        return (HCl.responseStatus res, headers, body)
----

Best regards,
Jos van den Oever
_______________________________________________
web-devel mailing list
web-devel@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/web-devel