the fromJust should never fail, beceause of the guard statement:<div><br></div><div>    | 300 &lt;= code &amp;&amp; code &lt; 400 &amp;&amp; isJust l&#39;&#39; &amp;&amp; isJust l&#39; = Just $ req</div><div><br></div><div>

Because of the order of the &amp;&amp; operators, it will only evaluate fromJust after it makes sure that the argument isJust. That function in particular shouldn&#39;t throw any exceptions - it should only return Nothing.</div>

<div><br></div><div>Knowing that, I don&#39;t quite think I understand what your concern is. Can you elaborate?</div><div><br></div><div>Thanks,</div><div>Myles</div><div><br><div class="gmail_quote">On Thu, Jan 26, 2012 at 12:59 AM, Michael Snoyman <span dir="ltr">&lt;<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I&#39;m a little worried about the use of `fromJust`, it will give users a<br>
very confusing error message, and the error might be trigged at the<br>
wrong point in the computation. I&#39;d feel better if checkRedirect lived<br>
in either some Failure, an Either, or maybe even in IO itself. IO<br>
might make sense if we want to implement some cookie jar functionality<br>
in the future via mutable references.<br>
<br>
Michael<br>
<br>
On Thu, Jan 26, 2012 at 10:29 AM, Myles C. Maxfield<br>
<div class="HOEnZb"><div class="h5">&lt;<a href="mailto:myles.maxfield@gmail.com">myles.maxfield@gmail.com</a>&gt; wrote:<br>
&gt; Here is a patch regarding getRedirectedRequest. Comments are very welcome.<br>
&gt;<br>
&gt; --Myles C. Maxfield<br>
&gt;<br>
&gt;<br>
&gt; On Wed, Jan 25, 2012 at 10:21 PM, Myles C. Maxfield<br>
&gt; &lt;<a href="mailto:myles.maxfield@gmail.com">myles.maxfield@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; I was planning on making the caller deal with keeping track of cookies<br>
&gt;&gt; between requests. My cookie idea only solves the problem of cookies<br>
&gt;&gt; persisting through a redirect chain - not between subsequent request chains.<br>
&gt;&gt;<br>
&gt;&gt; Do you think that Network.HTTP.Conduit should have a persistent cookie jar<br>
&gt;&gt; between caller&#39;s requests? I don&#39;t really think so.<br>
&gt;&gt;<br>
&gt;&gt; --Myles<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On Wed, Jan 25, 2012 at 9:28 PM, Michael Snoyman &lt;<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Wed, Jan 25, 2012 at 8:18 PM, Myles C. Maxfield<br>
&gt;&gt;&gt; &lt;<a href="mailto:myles.maxfield@gmail.com">myles.maxfield@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; &gt; Alright, that&#39;s fine. I just wanted to be explicit about the interface<br>
&gt;&gt;&gt; &gt; we&#39;d<br>
&gt;&gt;&gt; &gt; be providing. Taking the Request construction code out of &#39;http&#39; and<br>
&gt;&gt;&gt; &gt; putting<br>
&gt;&gt;&gt; &gt; it into its own function should be a quick change - I&#39;ll have it to you<br>
&gt;&gt;&gt; &gt; soon. One possible wrench - The existing code copies some fields (like<br>
&gt;&gt;&gt; &gt; the<br>
&gt;&gt;&gt; &gt; proxy) from the original request. In order to keep this functionality,<br>
&gt;&gt;&gt; &gt; the<br>
&gt;&gt;&gt; &gt; signature would have to be:<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; checkRedirect :: Request m -&gt; Response -&gt; Maybe (Request m)<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; Is that okay with you? I think I&#39;d also like to call the function<br>
&gt;&gt;&gt; &gt; something<br>
&gt;&gt;&gt; &gt; different, perhaps &#39;getRedirectedRequest&#39;. Is that okay? I&#39;ll also add<br>
&gt;&gt;&gt; &gt; an<br>
&gt;&gt;&gt; &gt; example to the documentation about how a caller would get the<br>
&gt;&gt;&gt; &gt; redirection<br>
&gt;&gt;&gt; &gt; chain by re-implementing redirection (by using the example in your<br>
&gt;&gt;&gt; &gt; previous<br>
&gt;&gt;&gt; &gt; email).<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Sounds great.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &gt; As for cookie handling - I think Network.Browser has a pretty elegant<br>
&gt;&gt;&gt; &gt; solution to this. They allow a &quot;CookieFilter&quot; which has type<br>
&gt;&gt;&gt; &gt; of URI -&gt; Cookie -&gt; IO Bool. Cookies are only put in the cookie jar if<br>
&gt;&gt;&gt; &gt; the<br>
&gt;&gt;&gt; &gt; function returns True. There is a default CookieFilter, which behaves<br>
&gt;&gt;&gt; &gt; as we<br>
&gt;&gt;&gt; &gt; would expect, but the user can override this function. That way, if you<br>
&gt;&gt;&gt; &gt; don&#39;t want to support cookies, you can just pass in (\ _ _ -&gt; return<br>
&gt;&gt;&gt; &gt; False).<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Also sounds good.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &gt; If we&#39;re already expecting people that want specific functionality to<br>
&gt;&gt;&gt; &gt; re-implement the redirect-following code, this solution might be<br>
&gt;&gt;&gt; &gt; unnecessary. Do you think that such a concept would be beneficial for<br>
&gt;&gt;&gt; &gt; Network.HTTP.Conduit to implement?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Yes, I can imagine that some people would want more fine-grained<br>
&gt;&gt;&gt; control of which cookies are accepted.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; &gt; Either way, I&#39;ll probably end up making a solution similar to your<br>
&gt;&gt;&gt; &gt; checkRedirect function that will just allow people to take SetCookies<br>
&gt;&gt;&gt; &gt; out of<br>
&gt;&gt;&gt; &gt; a Response and put Cookies into a Request. I&#39;ll probably also provide a<br>
&gt;&gt;&gt; &gt; default function which converts a SetCookie into a cookie by looking up<br>
&gt;&gt;&gt; &gt; the<br>
&gt;&gt;&gt; &gt; current time, inspecting the Request, etc. This will allow me to not<br>
&gt;&gt;&gt; &gt; have to<br>
&gt;&gt;&gt; &gt; change the type of Request or Response - the functions I&#39;ll be writing<br>
&gt;&gt;&gt; &gt; can<br>
&gt;&gt;&gt; &gt; deal with the raw Headers that are already in Requests and Responses.<br>
&gt;&gt;&gt; &gt; Modifying &#39;http&#39; to use these functions will be straightforward.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; How does this sound to you?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Sounds like a good plan to me. I&#39;m not entirely certain how you&#39;re<br>
&gt;&gt;&gt; planning on implementing the cookie jar itself. In other words, if I<br>
&gt;&gt;&gt; make a request, have a cookie set, and then make another request<br>
&gt;&gt;&gt; later, where will the cookie be stored in the interim, and how will<br>
&gt;&gt;&gt; the second request know to use it?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Michael<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
</div></div></blockquote></div><br></div>