<div dir="ltr">Can you provide:<br><br>* A complete file<div>* The error messages you're getting</div></div><br><div class="gmail_quote">On Thu, Mar 26, 2015 at 9:10 PM Jos van den Oever <<a href="mailto:jos@vandenoever.info">jos@vandenoever.info</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tuesday 24 March 2015 07:01:39 Michael Snoyman wrote:<br>
> On Sun, Mar 22, 2015 at 10:01 AM Jos van den Oever <<a href="mailto:jos@vandenoever.info" target="_blank">jos@vandenoever.info</a>><br>
><br>
> wrote:<br>
> > On Sunday 08 March 2015 07:28:30 you wrote:<br>
> > > I've updated that Gist to be compatible with WAI 3.0. The basic changes<br>
> > > I<br>
> > > made were:<br>
> > ><br>
> > > 1. Change the way Warp settings are applied (no longer use record<br>
> > > syntax,<br>
> > > but explicit set* functions).<br>
> > > 2. conduit is no longer the standard streaming interface for WAI, so<br>
> > > imported Network.Wai.Conduit and used helper functions from there.<br>
> > > 3. The specific question you asked about: the semantics for how to do<br>
> > > resource allocation in an application have changed. There were some<br>
> > > holes<br>
> > > in the previous approach that allowed async exceptions to leak in at the<br>
> > > wrong time. Instead, WAI 3.0 uses a similar interface to most resource<br>
> > > allocation functions in Haskell (like bracket or withFile).<br>
> > > Specifically,<br>
> > ><br>
> > > this looks like:<br>
> > > HCl.withResponse req2 man $ \res -> do<br>
> > ><br>
> > > let body = mapOutput (Chunk . fromByteString) $<br>
> > ><br>
> > > HCC.bodyReaderSource $ HCl.responseBody res<br>
> > ><br>
> > > headers = filter safeResHeader $ HCl.responseHeaders res<br>
> > ><br>
> > > respond $ responseSource (HCl.responseStatus res) headers body<br>
> ><br>
> > I'd like my proxy to be a caching proxy so each request shoule be saved to<br>
> > a<br>
> > file. I've tried adding an additional sink, (sinkFile) or conduit<br>
> > (conduitFie)<br>
> > to the HCC.bodyReaderSource, but cannot it right. What would be a good way<br>
> > to<br>
> > do this?<br>
><br>
> What have you tried so far?<br>
<br>
This is the code I have so far. I've annotated with a types. This code gives a<br>
compile error because of the line 'source2 = bodySource C.=$= fileSaver'. The<br>
MonadResource is not arising from the use in fileSaver. Somehow, I've to get<br>
runResourceT in there.<br>
<br>
===<br>
HCl.withResponse req2 man $ \res -> do<br>
--saver <- CB.conduitFile "/tmp/out"<br>
<br>
let path = "/tmp/out" :: FilePath<br>
fileSaver :: MonadResource m => C.Conduit S8.ByteString m<br>
S8.ByteString<br>
fileSaver = CB.conduitFile path<br>
bodyReader :: HCl.BodyReader<br>
bodyReader = HCl.responseBody res<br>
bodySource :: MonadIO m => C.ConduitM () S8.ByteString m ()<br>
bodySource = HCC.bodyReaderSource bodyReader<br>
source2 = bodySource C.=$= fileSaver<br>
chunk :: S8.ByteString -> C.Flush Builder<br>
chunk = C.Chunk . fromByteString<br>
body :: C.ConduitM () (C.Flush Builder) IO()<br>
body = C.mapOutput chunk source2<br>
headers = filter removeEncodingHeaders $ HCl.responseHeaders res<br>
<br>
time <- getPOSIXTime<br>
runSqlPool (insert_ $ Response (round time) reqid Nothing) pool<br>
respond $ WC.responseSource (HCl.responseStatus res) headers body<br>
===<br>
<br>
Cheers,<br>
Jos<br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
web-devel mailing list<br>
<a href="mailto:web-devel@haskell.org" target="_blank">web-devel@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/web-devel" target="_blank">http://mail.haskell.org/cgi-<u></u>bin/mailman/listinfo/web-devel</a><br>
</blockquote></div>