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-linkedin: apply dune fmt

Pure formatting changes from `dune fmt`: doc comment placement moves
from above the binding to below it for `type`s, multi-line `match`
expressions collapse onto one line where they fit, and infix operator
applications pick up spaces (`Soup.($?)` -> `Soup.( $? )`). No
semantic changes.

+36 -18
+29 -18
README.md
··· 11 11 - **`cookie.jar`** (module `Cookie_jar`): Cookie jar storage with domain/path 12 12 matching, delta tracking, and persistence in Mozilla format. 13 13 14 + ## Installation 15 + 16 + Install with opam: 17 + 18 + ```sh 19 + opam install cookie 20 + ``` 21 + 22 + If opam cannot find the package, it may not yet be released in the public 23 + `opam-repository`. Add the overlay repository, then install it: 24 + 25 + ```sh 26 + opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git 27 + opam update 28 + opam install cookie 29 + ``` 30 + 14 31 ## Cookie Attributes 15 32 16 - - **Domain**: Tail matching for hostnames, exact match for IPs 33 + - **Domain**: Tail matching for hostnames, exact 34 + match for IPs 17 35 - **Path**: Prefix matching with "/" separator 18 36 - **Secure**: HTTPS-only transmission 19 37 - **HttpOnly**: No JavaScript access ··· 74 92 ### Cookie Jar 75 93 76 94 ```ocaml 77 - (* Create an empty cookie jar *) 78 - let jar = Cookie_jar.v () in 79 - 80 - (* Add a cookie *) 81 - Cookie_jar.add_cookie jar cookie; 95 + let jar = Cookie_jar.v () 96 + let () = Cookie_jar.add_cookie jar cookie 82 97 83 - (* Get cookies matching a request URL *) 84 - let cookies = 98 + let matching = 85 99 Cookie_jar.cookies jar 86 100 ~clock 87 101 ~domain:"example.com" 88 102 ~path:"/api" 89 103 ~is_secure:true 90 - in 91 104 92 - (* Generate Cookie header *) 93 - let header = Cookie.cookie_header cookies 105 + let header = Cookie.cookie_header matching 94 106 ``` 95 107 96 108 ### Delta Tracking 97 109 98 110 ```ocaml 99 - (* Track which cookies were added since jar creation *) 100 - let new_cookies = Cookie_jar.delta jar in 101 - List.iter (fun c -> print_endline (Cookie.set_cookie_header c)) new_cookies 111 + let new_cookies = Cookie_jar.delta jar 112 + let () = 113 + List.iter 114 + (fun c -> print_endline (Cookie.set_cookie_header c)) 115 + new_cookies 102 116 ``` 103 117 104 118 ### Persistence ··· 106 120 Cookies are persisted in Mozilla format: 107 121 108 122 ```ocaml 109 - (* Save to file *) 110 - Cookie_jar.save path jar; 111 - 112 - (* Load from file (needs clock for access times) *) 123 + let () = Cookie_jar.save path jar 113 124 let jar = Cookie_jar.load ~clock path 114 125 ``` 115 126
+1
cookie.opam
··· 25 25 "publicsuffix" 26 26 "eio_main" 27 27 "alcotest" {with-test} 28 + "mdx" {with-test} 28 29 "odoc" {with-doc} 29 30 ] 30 31 build: [
+4
dune
··· 1 1 (env 2 2 (dev 3 3 (flags :standard %{dune-warnings}))) 4 + 5 + (mdx 6 + (files README.md) 7 + (libraries cookie cookie.jar ptime.clock.os))
+2
dune-project
··· 1 1 (lang dune 3.21) 2 + (using mdx 0.4) 2 3 3 4 (name cookie) 4 5 ··· 29 30 publicsuffix 30 31 eio_main 31 32 (alcotest :with-test) 33 + (mdx :with-test) 32 34 (odoc :with-doc)))