<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Http_cookies__Cookie (http-cookies.Http_cookies__Cookie)</title><link rel="stylesheet" href="../../odoc.css"/><meta charset="utf-8"/><meta name="generator" content="odoc 1.5.2"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../../highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body><div class="content"><header><nav><a href="../index.html">Up</a> â€“ <a href="../index.html">http-cookies</a> &#x00BB; Http_cookies__Cookie</nav><h1>Module <code>Http_cookies__Cookie</code></h1><p>A comprehensive and standards compliant HTTP cookies library for ocaml.</p><p>HTTP cookies are serialized as follows:</p><ul><li>In a <code>Cookie</code> header in a HTTP request</li><li>In a <code>Set-Cookie</code> header in a HTTP response.</li></ul><p>The library supports consuming and creating HTTP cookies in both requests and responses.</p><p>The standard implemented by the library is <a href="https://tools.ietf.org/html/rfc6265">RFC 6265</a>.</p><nav class="toc"><ul><li><a href="#types">Types</a></li><li><a href="#constructors">Constructors</a></li><li><a href="#query-cookie-attributes">Query Cookie Attributes</a></li><li><a href="#compare">Compare</a></li></ul></nav></header><section><header><h2 id="types"><a href="#types" class="anchor"></a>Types</h2></header><dl><dt class="spec module" id="module-Same_site"><a href="#module-Same_site" class="anchor"></a><code><span class="keyword">module</span> <a href="Same_site/index.html">Same_site</a> : <span class="keyword">sig</span> ... <span class="keyword">end</span></code></dt><dd><p>Represents 'Same-site' cookie attribute. See https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00.</p></dd></dl><dl><dt class="spec type" id="type-t"><a href="#type-t" class="anchor"></a><code><span class="keyword">type</span> t</code></dt><dd><p>Represents a cookie name-value in <code>Cookie</code> request header or a set of cookie attributes in <code>Set-Cookie</code> response header.</p></dd></dl><dl><dt class="spec exception" id="exception-Cookie"><a href="#exception-Cookie" class="anchor"></a><code><span class="keyword">exception</span> </code><code><span class="exception">Cookie</span> <span class="keyword">of</span> string</code></dt></dl></section><section><header><h2 id="constructors"><a href="#constructors" class="anchor"></a>Constructors</h2></header><dl><dt class="spec value" id="val-create"><a href="#val-create" class="anchor"></a><code><span class="keyword">val</span> create : <span>?&#8288;path:string</span> <span>&#45;&gt;</span> <span>?&#8288;domain:string</span> <span>&#45;&gt;</span> <span>?&#8288;expires:Unix.tm</span> <span>&#45;&gt;</span> <span>?&#8288;max_age:int</span> <span>&#45;&gt;</span> <span>?&#8288;secure:bool</span> <span>&#45;&gt;</span> <span>?&#8288;http_only:bool</span> <span>&#45;&gt;</span> <span>?&#8288;same_site:<a href="Same_site/index.html#type-t">Same_site.t</a></span> <span>&#45;&gt;</span> <span>?&#8288;extension:string</span> <span>&#45;&gt;</span> string <span>&#45;&gt;</span> <span>value:string</span> <span>&#45;&gt;</span> <a href="index.html#type-t">t</a></code></dt><dd><p><code>create ~path ~domain ~expires ~max_age ~secure ~http_only ~same_site ~extension name
    ~value</code> returns a cookie instance <a href="index.html#type-t"><code>t</code></a> with cookie name <code>name</code> and value <code>value</code> along with the given attributes.</p><dl><dt>raises Cookie</dt><dd><p>if any of the cookie attributes fail validation.</p></dd></dl></dd></dl><dl><dt class="spec value" id="val-of_cookie_header"><a href="#val-of_cookie_header" class="anchor"></a><code><span class="keyword">val</span> of_cookie_header : string <span>&#45;&gt;</span> <span><a href="index.html#type-t">t</a> list</span></code></dt><dd><p><code>of_cookie_header s</code> parses <code>s</code> - a string value which represents HTTP <code>Cookie</code> header value as defined in <a href="https://tools.ietf.org/html/rfc6265#section-4.2">https://tools.ietf.org/html/rfc6265#section-4.2</a> and returns a list of <code>Cookie</code>s.</p><h5 id="examples"><a href="#examples" class="anchor"></a>Examples</h5><p>This returns two cookies with cookie names <code>SID</code> and <code>lang-en</code>.</p><pre><code class="ml">Cookie.of_cookie_header &quot;SID=31d4d96e407aad42; lang=en-US&quot; </code></pre></dd></dl><dl><dt class="spec value" id="val-to_set_cookie_header_value"><a href="#val-to_set_cookie_header_value" class="anchor"></a><code><span class="keyword">val</span> to_set_cookie_header_value : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string</code></dt><dd><p><code>to_set_header c</code> serializes cookie <code>c</code> into a string which can be encoded as value for HTTP <code>Set-Cookie</code> header.</p><p>The datetime format for <code>expires</code> attribute is specified in <a href="https://tools.ietf.org/html/rfc2616#section-3.3.1">RFC 2616</a></p><p>Example of a string returned by the function,</p><pre>SID=31d4d96e407aad42; Path=/; Secure; HttpOnly; Expires=Sun, 06 Nov 1994 08:49:37 GMT</pre></dd></dl><dl><dt class="spec value" id="val-to_cookie_header_value"><a href="#val-to_cookie_header_value" class="anchor"></a><code><span class="keyword">val</span> to_cookie_header_value : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string</code></dt><dd><p><code>to_cookie_header c</code> serializes <code>c</code> into a string which can be encoded as value for HTTP <code>Cookie</code> header.</p><p>Example of a string returned by the function.</p><pre>SID=31d4d96e407aad42</pre></dd></dl></section><section><header><h2 id="query-cookie-attributes"><a href="#query-cookie-attributes" class="anchor"></a>Query Cookie Attributes</h2><p>Cookie attributes are defined precisely at <a href="https://tools.ietf.org/html/rfc6265#section-4.1.1">RFC 6262</a></p></header><dl><dt class="spec value" id="val-name"><a href="#val-name" class="anchor"></a><code><span class="keyword">val</span> name : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string</code></dt><dd><p><code>name t</code> returns a cookie name.</p><p>See <a href="https://tools.ietf.org/html/rfc6265#section-4.1.1">cookie-name</a></p></dd></dl><dl><dt class="spec value" id="val-value"><a href="#val-value" class="anchor"></a><code><span class="keyword">val</span> value : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> string</code></dt><dd><p><code>value t</code> returns a cookie value.</p><p>See <a href="https://tools.ietf.org/html/rfc6265#section-4.1.1">cookie-value</a></p></dd></dl><dl><dt class="spec value" id="val-path"><a href="#val-path" class="anchor"></a><code><span class="keyword">val</span> path : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span>string option</span></code></dt><dd><p><code>path t</code> returns cookie path attribute.</p><p>See <a href="https://tools.ietf.org/html/rfc6265#section-5.2.4">cookie-path</a></p></dd></dl><dl><dt class="spec value" id="val-domain"><a href="#val-domain" class="anchor"></a><code><span class="keyword">val</span> domain : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span>string option</span></code></dt><dd><p><code>domain t</code> returns cookie domain attribute.</p><p>See <a href="https://tools.ietf.org/html/rfc6265#section-4.1.2.3">cookie-domain</a></p></dd></dl><dl><dt class="spec value" id="val-expires"><a href="#val-expires" class="anchor"></a><code><span class="keyword">val</span> expires : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span>Unix.tm option</span></code></dt><dd><p><code>expires t</code> returns a coookie expires attribute.</p><p>See <a href="https://tools.ietf.org/html/rfc6265#section-4.1.2.1.">cookie-expires</a></p></dd></dl><dl><dt class="spec value" id="val-max_age"><a href="#val-max_age" class="anchor"></a><code><span class="keyword">val</span> max_age : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span>int option</span></code></dt><dd><p><code>max_age t</code> returns a cookie max_age attribute.</p><p>See <a href="https://tools.ietf.org/html/rfc6265#section-4.1.2.2">max-age</a> and <a href="https://tools.ietf.org/html/rfc6265#section-4.1.1">max-age-av</a></p></dd></dl><dl><dt class="spec value" id="val-secure"><a href="#val-secure" class="anchor"></a><code><span class="keyword">val</span> secure : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span>bool option</span></code></dt><dd><p><code>secure t</code> returns a secure attribute.</p><p>See <a href="https://tools.ietf.org/html/rfc6265#section-4.1.2.5">cookie-secure</a></p></dd></dl><dl><dt class="spec value" id="val-http_only"><a href="#val-http_only" class="anchor"></a><code><span class="keyword">val</span> http_only : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span>bool option</span></code></dt><dd><p><code>http_only t</code> returns a http_only attribute.</p><p>See <a href="https://tools.ietf.org/html/rfc6265#section-4.1.2.6">http-only</a></p></dd></dl><dl><dt class="spec value" id="val-same_site"><a href="#val-same_site" class="anchor"></a><code><span class="keyword">val</span> same_site : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span><a href="Same_site/index.html#type-t">Same_site.t</a> option</span></code></dt><dd><p><code>same_site t</code> returns a same_site attribute.</p><p>See <a href="https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00">same-site</a></p></dd></dl><dl><dt class="spec value" id="val-extension"><a href="#val-extension" class="anchor"></a><code><span class="keyword">val</span> extension : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <span>string option</span></code></dt><dd><p><code>extension t</code> returns a cookie extension value.</p><p>See <a href="https://tools.ietf.org/html/rfc6265#section-4.1.1">cookie-extension</a></p></dd></dl></section><section><header><h2 id="compare"><a href="#compare" class="anchor"></a>Compare</h2></header><dl><dt class="spec value" id="val-compare"><a href="#val-compare" class="anchor"></a><code><span class="keyword">val</span> compare : <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> <a href="index.html#type-t">t</a> <span>&#45;&gt;</span> int</code></dt><dd><p><code>compare c1 c2</code> returns <code>0</code> if <code>c1</code> and <code>c2</code> are equal, a positive integer if <code>c1</code> is greater than <code>c2</code> and a negative integer if <code>c1</code> is less than <code>c2</code></p></dd></dl></section></div></body></html>