package http-cookie
Install
Dune Dependency
Authors
Maintainers
Sources
md5=b837250b924eb52aadf1342007c776db
sha512=c9d1e86c83c2e9b440cf22d7d0d37a31da358e95ff2eda2158de164c0add937c626076ca0465b17c2aca1edf0305d1f74e4720bd45edfa938651d340556038ee
Description
A comprehensive and strict standards compliant HTTP cookies library for ocaml.
http-cookie supports consuming and creating HTTP cookies found in HTTP request Cookie header and in Set-Cookie header in HTTP response. The library validates all cookie attributes, cookie name and cookie value for standards conformance and correct usage. The validation suite is comprehensive and includes validation of domain name, IPv4, IPv6 and HTTP date-time formats.
The RFC standards/validations implemented by the library are:
- RFC 6265
- RFC 1123
- RFC 1034
- IPV4/IPV6 address validation
Published: 18 Jan 2023
README
Http-cookie
A comprehensive and strict standards compliant HTTP cookies library for ocaml. API Documentation
http-cookie
supports consuming and creating HTTP cookies found in HTTP request Cookie
header and in Set-Cookie
header in HTTP response. The library validates all cookie attributes, cookie name and cookie value for standards conformance and correct usage. The validation suite is comprehensive and includes validation of domain name, IPv4, IPv6 and HTTP date-time formats.
The RFC standards implemented by the library are:
Cookies - RFC 6265 - Strict standards compliance.
HTTP Date - RFC 1123 - HTTP date time format specification.
Domain Name - RFC 1034 - Domain name format specification.
Hosts - RFC 1123 - Host name format specification.
IPv4/IPv6 - IPv4 and IPv6 address format specification.
Usage
let pp = function
| Ok cookie -> Format.printf "%a\n" Http_cookie.pp cookie
| Error err -> Format.printf "Err: %s" err
HTTP Cookie
header value:
# let s = "SID=234234asdasdasda" in
let c = List.nth (Http_cookie.of_cookie s |> Result.get_ok) 0 in
let s1 = Http_cookie.to_cookie c in
s = s1 ;;
- : bool = true
HTTP Set-Cookie
header value:
# let s = "SID=31d4d96e407aad42; Path=/; Domain=ffff::0234:ddd:192.168.0.1; Expires=Sun, 06 Nov 1994 08:49:37 GMT; Secure; HttpOnly" in
let c = Http_cookie.of_set_cookie s |> Result.get_ok in
let s2 = Http_cookie.to_set_cookie c in
s = s2;;
- : bool = true
Create HTTP cookie:
# Http_cookie.create ~path:"/home" ~domain:"eee:aaa:abdf::223:192.168.0.1" ~secure:true ~same_site:`Strict ~name:"SID" "31d4d96e407aad42" |> pp;;
name: SID
value: 31d4d96e407aad42
path: /home
domain: eee:aaa:abdf::223:192.168.0.1
expires:
max_age:
secure: true
http_only: true
same_site: Strict
extension:
- : unit = ()