OCaml HTTP cookie handling library with support for Eio-based storage jars

correct date format

+24 -5
+22 -2
lib/core/cookeio.ml
··· 502 502 parse_fmt2 s <|> fun () -> 503 503 parse_fmt3 s <|> fun () -> 504 504 parse_fmt4 s 505 + 506 + (** Format a Ptime.t as an HTTP-date (rfc1123-date format). 507 + 508 + Per {{:https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1} RFC 6265 Section 4.1.1}, 509 + the Expires attribute uses sane-cookie-date which references 510 + {{:https://datatracker.ietf.org/doc/html/rfc1123#section-5.2.14} RFC 1123 Section 5.2.14}. 511 + 512 + Format: "Sun, 06 Nov 1994 08:49:37 GMT" 513 + 514 + @see <https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1> RFC 6265 Section 4.1.1 *) 515 + let format_http_date time = 516 + let (year, month, day), ((hour, min, sec), _tz_offset) = Ptime.to_date_time time in 517 + let weekday = match Ptime.weekday time with 518 + | `Sun -> "Sun" | `Mon -> "Mon" | `Tue -> "Tue" | `Wed -> "Wed" 519 + | `Thu -> "Thu" | `Fri -> "Fri" | `Sat -> "Sat" 520 + in 521 + let month_name = [| ""; "Jan"; "Feb"; "Mar"; "Apr"; "May"; "Jun"; 522 + "Jul"; "Aug"; "Sep"; "Oct"; "Nov"; "Dec" |].(month) in 523 + Printf.sprintf "%s, %02d %s %04d %02d:%02d:%02d GMT" 524 + weekday day month_name year hour min sec 505 525 end 506 526 507 527 (** {1 Cookie Parsing} *) ··· 891 911 (Ptime.Span.to_int_s span)) 892 912 (max_age cookie); 893 913 894 - (* Add Expires if present *) 914 + (* Add Expires if present - using RFC 1123 date format per RFC 6265 Section 4.1.1 *) 895 915 Option.iter 896 916 (function 897 917 | `Session -> Buffer.add_string buffer "; Expires=0" 898 918 | `DateTime exp_time -> 899 - let exp_str = Ptime.to_rfc3339 ~tz_offset_s:0 exp_time in 919 + let exp_str = DateParser.format_http_date exp_time in 900 920 Buffer.add_string buffer (Printf.sprintf "; Expires=%s" exp_str)) 901 921 (expires cookie); 902 922
+2 -3
lib/core/cookeio.mli
··· 527 527 Includes all cookie attributes: Max-Age, Expires, Domain, Path, Secure, 528 528 HttpOnly, Partitioned, and SameSite. 529 529 530 - Note: The Expires attribute is currently formatted using RFC 3339 format, 531 - which differs from the RFC-recommended rfc1123-date format specified in 532 - {{:https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1} Section 4.1.1}. 530 + The Expires attribute uses rfc1123-date format ("Sun, 06 Nov 1994 08:49:37 GMT") 531 + as specified in {{:https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1} Section 4.1.1}. 533 532 534 533 @see <https://datatracker.ietf.org/doc/html/rfc6265#section-4.1> RFC 6265 Section 4.1 - The Set-Cookie Header *) 535 534