[Haskell-cafe] Network.Curl cookie jar madness

Brandon Allbery allbery.b at gmail.com
Sun Aug 19 17:28:07 CEST 2012


On Sat, Aug 18, 2012 at 8:52 PM, Michael Orlitzky <michael at orlitzky.com>wrote:

> Curl is making the request, but if I remove the (hPutStrLn stderr
> response_body), it doesn't work! What's even more insane is, this works:
>
>   hPutStrLn stderr response_body
>
> and this doesn't:
>
>   hPutStrLn stdout response_body
>
> whaaaaaaatttttttt? I really don't want to dump the response body to
>

At a guess, this is laziness and buffering interacting:  stderr is usually
unbuffered since it's error or log output that one usually wants to see
immediately; stdout is usually line buffered unless redirected, in which
case it's block buffered.

The real issue is that you (or perhaps Curl) is being too lazy and not
running the log_in until the result is actually needed; hPutStrLn is
forcing it, but incompletely when it's buffered.  (Which strikes me as
weird unless Curl is using unsafeInterleaveIO somewhere....)  You will need
to force it or hold the handle open until the content is fully evaluated;
if it's in the half-closed state that hGetContents sets, it's usually best
to not close the handle explicitly but let the implicit lazy close do it.

-- 
brandon s allbery                                      allbery.b at gmail.com
wandering unix systems administrator (available)     (412) 475-9364 vm/sms
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120819/6a48a652/attachment.htm>


More information about the Haskell-Cafe mailing list