<p>Sounds good. I think the nicest way to handle maxage would be changing SetCookie, not handling it at parsing time.</p>
<p>Aristid </p>
<div class="gmail_quote">Am 03.02.2012 05:35 schrieb &quot;Myles C. Maxfield&quot; &lt;<a href="mailto:myles.maxfield@gmail.com">myles.maxfield@gmail.com</a>&gt;:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Alright. After reading the spec, I have these questions / concerns:<div><ul><li>The spec supports the &quot;Max-Age&quot; cookie attribute, which Web.Cookies doesn&#39;t.</li><ul><li>I see two possible solutions to this. The first is to have parseSetCookie take a UTCTime as an argument which will represent the current time so it can populate the setCookieExpires field by adding the Max-Age attribute to the current time. Alternatively, that function can return an IO SetCookie so it can ask for the current time by itself (which I think is inferior to taking the current time as an argument). Note that the spec says to prefer Max-Age over Expires.</li>


<li>Add a field to SetCookie of type Maybe DiffTime which represents the Max-Age attribute</li></ul><li>Cookie code should be aware of the <a href="http://mxr.mozilla.org/mozilla-central/source/netwerk/dns/effective_tld_names.dat" target="_blank">Public Suffix List</a> as a part of its domain verification. The cookie code only needs to be able to tell if a specific string is in the list (W.Ascii -&gt; Bool)</li>


<ul><li>I propose making an entirely unrelated package, public-suffix-list, with a module Network.PublicSuffixList, which will expose this function, as well as functions about parsing the list itself. Thoughts?</li></ul>

<li>
Web.Cookie doesn&#39;t have a &quot;secure-only&quot; attribute. Adding one in is straightforward enough.</li><li>The spec describes cookies as a property of HTTP, not of the World Wide Web. Perhaps &quot;Web.Cookie&quot; should be renamed? Just a thought; it doesn&#39;t really matter to me.</li>


</ul>As for Network.HTTP.Conduit.Cookie, the spec describes in section 5.3 &quot;Storage Model&quot; what fields a Cookie has. Here is my proposal for the functions it will expose:</div><div><ul><li>receiveSetCookie :: SetCookie -&gt; Req.Request m -&gt; UTCTime -&gt; Bool -&gt; CookieJar -&gt; CookieJar</li>


<ul><li>Runs the algorithm described in section 5.3 &quot;Storage Model&quot;</li><li>The UTCTime is the current-time, the Bool is whether or not the caller is an HTTP-based API (as opposed to JavaScript or anything else)</li>


</ul><li>updateCookieJar :: Res.Response a -&gt; Req.Request m -&gt; UTCTime -&gt; CookieJar -&gt; (CookieJar, Res.Response a)</li><ul><li>Applies &quot;receiveSetCookie&quot; to a Response. The output CookieJar is stripped of any Set-Cookie headers.</li>


<li>Specifies &quot;True&quot; for the Bool in receiveSetCookie</li></ul><li>computeCookieString :: Req.Request m -&gt; CookieJar -&gt; UTCTime -&gt; Bool -&gt; (W.Ascii, CookieJar)</li><ul><li>Runs the algorithm described in section 5.4 &quot;The Cookie Header&quot;</li>


<li>The UTCTime and Bool are the same as in receiveSetCookie</li></ul><li>insertCookiesIntoRequest :: Req.Request m -&gt; CookieJar -&gt; UTCTime -&gt; (Req.Request m, CookieJar)</li><ul><li>Applies &quot;computeCookieString&quot; to a Request. The output cookie jar has updated last-accessed-times.</li>


<li>Specifies &quot;True&quot; for the Bool in computeCookieString</li></ul><li>evictExpiredCookies :: CookieJar -&gt; UTCTime -&gt; CookieJar</li><ul><li>Runs the algorithm described in the last part of section 5.3 &quot;Storage Model&quot;</li>


</ul></ul><div>This will make the relevant part of &#39;http&#39; look like:</div><div><br></div><div><div>    go count req&#39;&#39; cookie_jar&#39;&#39; = do</div><div>        now &lt;- liftIO $ getCurrentTime</div><div>


        let (req&#39;, cookie_jar&#39;) = insertCookiesIntoRequest req&#39;&#39; (evictExpiredCookies cookie_jar&#39;&#39; now) now</div><div>        res&#39; &lt;- httpRaw req&#39; manager</div><div>        let (cookie_jar, res) = updateCookieJar res&#39; req&#39; now cookie_jar&#39;</div>


<div>        case getRedirectedRequest req&#39; (responseHeaders res) (W.statusCode (statusCode res)) of</div><div>            Just req -&gt; go (count - 1) req cookie_jar</div><div>            Nothing -&gt; return res</div>


</div><div><br></div><div>I plan to not allow for a user-supplied cookieFilter function. If they want that functionality, they can re-implement the redirection-following logic.</div><div><br></div><div>Any thoughts on any of this?</div>


<div><br></div><div>Thanks,<br>Myles</div><br><div class="gmail_quote">On Wed, Feb 1, 2012 at 5:19 PM, Myles C. Maxfield <span dir="ltr">&lt;<a href="mailto:myles.maxfield@gmail.com" target="_blank">myles.maxfield@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p>Nope. I&#39;m not. The RFC is very explicit about how to handle cookies. As soon as I&#39;m finished making sense of it (in terms of Haskell) I&#39;ll send another proposal email.</p>


<div><div>
<div class="gmail_quote">On Feb 1, 2012 3:25 AM, &quot;Michael Snoyman&quot; &lt;<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>&gt; wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">



You mean you&#39;re *not* making this proposal?<br>
<br>
On Wed, Feb 1, 2012 at 7:30 AM, Myles C. Maxfield<br>
&lt;<a href="mailto:myles.maxfield@gmail.com" target="_blank">myles.maxfield@gmail.com</a>&gt; wrote:<br>
&gt; Well, this is embarrassing. Please disregard my previous email. I should<br>
&gt; learn to read the RFC *before* submitting proposals.<br>
&gt;<br>
&gt; --Myles<br>
&gt;<br>
&gt;<br>
&gt; On Tue, Jan 31, 2012 at 6:37 PM, Myles C. Maxfield<br>
&gt; &lt;<a href="mailto:myles.maxfield@gmail.com" target="_blank">myles.maxfield@gmail.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Here are my initial ideas about supporting cookies. Note that I&#39;m using<br>
&gt;&gt; Chrome for ideas since it&#39;s open source.<br>
&gt;&gt;<br>
&gt;&gt; Network/HTTP/Conduit/Cookies.hs file<br>
&gt;&gt; Exporting the following symbols:<br>
&gt;&gt;<br>
&gt;&gt; type StuffedCookie = SetCookie<br>
&gt;&gt;<br>
&gt;&gt; A regular SetCookie can have Nothing for its Domain and Path attributes. A<br>
&gt;&gt; StuffedCookie has to have these fields set.<br>
&gt;&gt;<br>
&gt;&gt; type CookieJar = [StuffedCookie]<br>
&gt;&gt;<br>
&gt;&gt; Chrome&#39;s cookie jar is implemented as (the C++ equivalent of) Map W.Ascii<br>
&gt;&gt; StuffedCookie. The key is the &quot;eTLD+1&quot; of the domain, so lookups for all<br>
&gt;&gt; cookies for a given domain are fast.<br>
&gt;&gt; I think I&#39;ll stay with just a list of StuffedCookies just to keep it<br>
&gt;&gt; simple. Perhaps a later revision can implement the faster map.<br>
&gt;&gt;<br>
&gt;&gt; getRelevantCookies :: Request m -&gt; CookieJar -&gt; UTCTime -&gt; (CookieJar,<br>
&gt;&gt; Cookies)<br>
&gt;&gt;<br>
&gt;&gt; Gets all the cookies from the cookie jar that should be set for the given<br>
&gt;&gt; Request.<br>
&gt;&gt; The time argument is whatever &quot;now&quot; is (it&#39;s pulled out of the function so<br>
&gt;&gt; the function can remain pure and easily testable)<br>
&gt;&gt; The function will also remove expired cookies from the cookie jar (given<br>
&gt;&gt; what &quot;now&quot; is) and return the filtered cookie jar<br>
&gt;&gt;<br>
&gt;&gt; putRelevantCookies :: Request m -&gt; CookieJar -&gt; [StuffedCookie] -&gt;<br>
&gt;&gt; CookieJar<br>
&gt;&gt;<br>
&gt;&gt; Insert cookies from a server response into the cookie jar.<br>
&gt;&gt; The first argument is only used for checking to see which cookies are<br>
&gt;&gt; valid (which cookies match the requested domain, etc, so <a href="http://site1.com" target="_blank">site1.com</a> can&#39;t set<br>
&gt;&gt; a cookie for <a href="http://site2.com" target="_blank">site2.com</a>)<br>
&gt;&gt;<br>
&gt;&gt; stuffCookie :: Request m -&gt; SetCookie -&gt; StuffedCookie<br>
&gt;&gt;<br>
&gt;&gt; If the SetCookie&#39;s fields are Nothing, fill them in given the Request from<br>
&gt;&gt; which it originated<br>
&gt;&gt;<br>
&gt;&gt; getCookies :: Response a -&gt; ([SetCookie], Response a)<br>
&gt;&gt;<br>
&gt;&gt; Pull cookies out of a server response. Return the response with the<br>
&gt;&gt; Set-Cookie headers filtered out<br>
&gt;&gt;<br>
&gt;&gt; putCookies :: Request a -&gt; Cookies -&gt; Request a<br>
&gt;&gt;<br>
&gt;&gt; A wrapper around renderCookies. Inserts some cookies into a request.<br>
&gt;&gt; Doesn&#39;t overwrite cookies that are already set in the request<br>
&gt;&gt;<br>
&gt;&gt; These functions will be exported from Network.HTTP.Conduit as well, so<br>
&gt;&gt; callers can use them to re-implement redirection chains<br>
&gt;&gt; I won&#39;t implement a cookie filtering function (like what Network.Browser<br>
&gt;&gt; has)<br>
&gt;&gt;<br>
&gt;&gt; If you want to have arbitrary handling of cookies, re-implement<br>
&gt;&gt; redirection following. It&#39;s not very difficult if you use the API provided,<br>
&gt;&gt; and the &#39;http&#39; function is open source so you can use that as a reference.<br>
&gt;&gt;<br>
&gt;&gt; I will implement the functions according to RFC 6265<br>
&gt;&gt; I will also need to write the following functions. Should they also be<br>
&gt;&gt; exported?<br>
&gt;&gt;<br>
&gt;&gt; canonicalizeDomain :: W.Ascii -&gt; W.Ascii<br>
&gt;&gt;<br>
&gt;&gt; turns &quot;..a.b.c..d.com...&quot; to &quot;<a href="http://a.b.c.d.com" target="_blank">a.b.c.d.com</a>&quot;<br>
&gt;&gt; Technically necessary for domain matching (Chrome does it)<br>
&gt;&gt; Perhaps unnecessary for a first pass? Perhaps we can trust users for now?<br>
&gt;&gt;<br>
&gt;&gt; domainMatches :: W.Ascii -&gt; W.Ascii -&gt; Maybe W.Ascii<br>
&gt;&gt;<br>
&gt;&gt; Does the first domain match against the second domain?<br>
&gt;&gt; If so, return the prefix of the first that isn&#39;t in the second<br>
&gt;&gt;<br>
&gt;&gt; pathMatches :: W.Ascii -&gt; W.Ascii -&gt; Bool<br>
&gt;&gt;<br>
&gt;&gt; Do the paths match?<br>
&gt;&gt;<br>
&gt;&gt; In order to implement domain matching, I have to have knowledge of<br>
&gt;&gt; the Public Suffix List so I know that <a href="http://sub1.sub2.pvt.k12.wy.us" target="_blank">sub1.sub2.pvt.k12.wy.us</a> can set a<br>
&gt;&gt; cookie for <a href="http://sub2.pvt.k12.wy.us" target="_blank">sub2.pvt.k12.wy.us</a> but not for <a href="http://k12.wy.us" target="_blank">k12.wy.us</a> (because <a href="http://pvt.k12.wy.us" target="_blank">pvt.k12.wy.us</a><br>




&gt;&gt; is a &quot;suffix&quot;). There are a variety of ways to implement this.<br>
&gt;&gt;<br>
&gt;&gt; As far as I can tell, Chrome does it by using a script (which a human<br>
&gt;&gt; periodically runs) which parses the list at creates a .cc file that is<br>
&gt;&gt; included in the build.<br>
&gt;&gt;<br>
&gt;&gt; I might be wrong about the execution of the script; it might be a build<br>
&gt;&gt; step. If it is a build step, however, it is suspicious that a build target<br>
&gt;&gt; would try to download a file...<br>
&gt;&gt;<br>
&gt;&gt; Any more elegant ideas?<br>
&gt;&gt;<br>
&gt;&gt; Feedback on any/all of the above would be very helpful before I go off<br>
&gt;&gt; into the weeds on this project.<br>
&gt;&gt;<br>
&gt;&gt; Thanks,<br>
&gt;&gt; Myles C. Maxfield<br>
&gt;&gt;<br>
&gt;&gt; On Sat, Jan 28, 2012 at 8:17 PM, Michael Snoyman &lt;<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>&gt;<br>
&gt;&gt; wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Thanks, looks great! I&#39;ve merged it into the Github tree.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On Sat, Jan 28, 2012 at 8:36 PM, Myles C. Maxfield<br>
&gt;&gt;&gt; &lt;<a href="mailto:myles.maxfield@gmail.com" target="_blank">myles.maxfield@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; &gt; Ah, yes, you&#39;re completely right. I completely agree that moving the<br>
&gt;&gt;&gt; &gt; function into the Maybe monad increases readability. This kind of<br>
&gt;&gt;&gt; &gt; function<br>
&gt;&gt;&gt; &gt; is what the Maybe monad was designed for.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; Here is a revised patch.<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; On Sat, Jan 28, 2012 at 8:28 AM, Michael Snoyman &lt;<a href="mailto:michael@snoyman.com" target="_blank">michael@snoyman.com</a>&gt;<br>
&gt;&gt;&gt; &gt; wrote:<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; On Sat, Jan 28, 2012 at 1:20 AM, Myles C. Maxfield<br>
&gt;&gt;&gt; &gt;&gt; &lt;<a href="mailto:myles.maxfield@gmail.com" target="_blank">myles.maxfield@gmail.com</a>&gt; wrote:<br>
&gt;&gt;&gt; &gt;&gt; &gt; the fromJust should never fail, beceause of the guard statement:<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;     | 300 &lt;= code &amp;&amp; code &lt; 400 &amp;&amp; isJust l&#39;&#39; &amp;&amp; isJust l&#39; = Just $<br>
&gt;&gt;&gt; &gt;&gt; &gt; req<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; Because of the order of the &amp;&amp; operators, it will only evaluate<br>
&gt;&gt;&gt; &gt;&gt; &gt; fromJust<br>
&gt;&gt;&gt; &gt;&gt; &gt; after it makes sure that the argument isJust. That function in<br>
&gt;&gt;&gt; &gt;&gt; &gt; particular<br>
&gt;&gt;&gt; &gt;&gt; &gt; shouldn&#39;t throw any exceptions - it should only return Nothing.<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; Knowing that, I don&#39;t quite think I understand what your concern is.<br>
&gt;&gt;&gt; &gt;&gt; &gt; Can<br>
&gt;&gt;&gt; &gt;&gt; &gt; you<br>
&gt;&gt;&gt; &gt;&gt; &gt; elaborate?<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; You&#39;re right, but I had to squint really hard to prove to myself that<br>
&gt;&gt;&gt; &gt;&gt; you&#39;re right. That&#39;s the kind of code that could easily be broken in<br>
&gt;&gt;&gt; &gt;&gt; future updates by an unwitting maintainer (e.g., me). To protect the<br>
&gt;&gt;&gt; &gt;&gt; world from me, I&#39;d prefer if the code didn&#39;t have the fromJust. This<br>
&gt;&gt;&gt; &gt;&gt; might be a good place to leverage the Monad instance of Maybe.<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; Michael<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
</blockquote></div>
</div></div></blockquote></div><br></div>
<br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div>