[Haskell-cafe] Network.Curl cookie jar madness

Iustin Pop iusty at k1024.org
Sun Aug 19 03:00:52 CEST 2012

On Sat, Aug 18, 2012 at 08:52:00PM -0400, Michael Orlitzky wrote:
> I'm one bug away from a working program and need some help. I wrote a
> little utility that logs into LWN.net, retrieves an article, and creates
> an epub out of it. Full code here:
>   git clone http://michael.orlitzky.com/git/lwn-epub.git
> This is the code that gets the login cookie:
>   cj <- make_cookie_jar
>   li_result <- log_in cj uname pword
>   case li_result of
>     Left err -> do
>       let msg = "Failed to log in. " ++ err
>       hPutStrLn stderr msg
>     Right response_body -> do
>       hPutStrLn stderr response_body
>   return $ cfg { C.cookie_jar = Just cj }
> 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
> stderr, but I can't even begin to imagine what's going on here. Has
> anyone got Network.Curl working with a cookie jar?

Is this perchance due to laziness? And the fact that stderr is not
buffered by default, so all output is forced right then (forcing the
evaluation), whereas stdout is buffered, so the output might only be
made later (or even after you to an hFlush).

I'd try to make sure that response_body is fully evaluated before
returning from the function.

Or I might be totally wrong, in which case sorry :)


More information about the Haskell-Cafe mailing list