Cookie parsing, validation, and jar management following RFC 6265.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ocaml-cookie: enable MDX on lib/core/cookie.mli, fix verbatim block

Add (mdx ...) stanza to lib/core/dune. The two odoc examples now use
Ptime.epoch as the deterministic clock and assert on the parsed cookie
fields (name, value, secure, http_only) so the build catches future
regressions in of_set_cookie_header / of_cookie_header.

In lib/jar/cookie_jar.mli, the Mozilla-format snippet was wrapped in
{[ ... ]} but is shell-tab pseudocode (not OCaml). Switched to {v ... v}
verbatim so it can be added to the mdx stanza later without false
parse errors.

+27 -8
+21 -6
lib/core/cookie.mli
··· 524 524 525 525 Example: 526 526 {[ 527 - of_set_cookie_header 528 - ~now:(fun () -> Ptime_clock.now ()) 529 - ~domain:"example.com" ~path:"/" "session=abc123; Secure; HttpOnly" 527 + let now () = Ptime.epoch 528 + 529 + let cookie = 530 + Cookie.of_set_cookie_header ~now ~domain:"example.com" ~path:"/" 531 + "session=abc123; Secure; HttpOnly" 532 + |> Result.get_ok 533 + 534 + let () = 535 + assert (Cookie.name cookie = "session"); 536 + assert (Cookie.value cookie = "abc123"); 537 + assert (Cookie.secure cookie); 538 + assert (Cookie.http_only cookie) 530 539 ]} 531 540 532 541 @see <https://datatracker.ietf.org/doc/html/rfc6265#section-5.2> ··· 565 574 566 575 Example: 567 576 {[ 568 - of_cookie_header 569 - ~now:(fun () -> Ptime_clock.now ()) 570 - ~domain:"example.com" ~path:"/" "session=abc; theme=dark" 577 + let now () = Ptime.epoch 578 + 579 + let cookies = 580 + Cookie.of_cookie_header ~now ~domain:"example.com" ~path:"/" 581 + "session=abc; theme=dark" 582 + |> Result.get_ok 583 + 584 + let names = List.map Cookie.name cookies 585 + let () = assert (names = [ "session"; "theme" ]) 571 586 ]} 572 587 573 588 @see <https://datatracker.ietf.org/doc/html/rfc6265#section-4.2>
+4
lib/core/dune
··· 2 2 (name cookie) 3 3 (public_name nox-cookie) 4 4 (libraries fmt logs ptime ipaddr domain-name publicsuffix)) 5 + 6 + (mdx 7 + (files cookie.mli) 8 + (libraries nox-cookie ptime))
+2 -2
lib/jar/cookie_jar.mli
··· 235 235 (** [to_mozilla_format t] serializes cookies in Mozilla/Netscape cookie format. 236 236 237 237 The Mozilla format uses tab-separated fields: 238 - {[ 238 + {v 239 239 domain \t include_subdomains \t path \t secure \t expires \t name \t value 240 - ]} 240 + v} 241 241 242 242 The [include_subdomains] field corresponds to the inverse of the 243 243 {{:https://datatracker.ietf.org/doc/html/rfc6265#section-5.3}