···502502 parse_fmt2 s <|> fun () ->
503503 parse_fmt3 s <|> fun () ->
504504 parse_fmt4 s
505505+506506+ (** Format a Ptime.t as an HTTP-date (rfc1123-date format).
507507+508508+ Per {{:https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1} RFC 6265 Section 4.1.1},
509509+ the Expires attribute uses sane-cookie-date which references
510510+ {{:https://datatracker.ietf.org/doc/html/rfc1123#section-5.2.14} RFC 1123 Section 5.2.14}.
511511+512512+ Format: "Sun, 06 Nov 1994 08:49:37 GMT"
513513+514514+ @see <https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1> RFC 6265 Section 4.1.1 *)
515515+ let format_http_date time =
516516+ let (year, month, day), ((hour, min, sec), _tz_offset) = Ptime.to_date_time time in
517517+ let weekday = match Ptime.weekday time with
518518+ | `Sun -> "Sun" | `Mon -> "Mon" | `Tue -> "Tue" | `Wed -> "Wed"
519519+ | `Thu -> "Thu" | `Fri -> "Fri" | `Sat -> "Sat"
520520+ in
521521+ let month_name = [| ""; "Jan"; "Feb"; "Mar"; "Apr"; "May"; "Jun";
522522+ "Jul"; "Aug"; "Sep"; "Oct"; "Nov"; "Dec" |].(month) in
523523+ Printf.sprintf "%s, %02d %s %04d %02d:%02d:%02d GMT"
524524+ weekday day month_name year hour min sec
505525end
506526507527(** {1 Cookie Parsing} *)
···891911 (Ptime.Span.to_int_s span))
892912 (max_age cookie);
893913894894- (* Add Expires if present *)
914914+ (* Add Expires if present - using RFC 1123 date format per RFC 6265 Section 4.1.1 *)
895915 Option.iter
896916 (function
897917 | `Session -> Buffer.add_string buffer "; Expires=0"
898918 | `DateTime exp_time ->
899899- let exp_str = Ptime.to_rfc3339 ~tz_offset_s:0 exp_time in
919919+ let exp_str = DateParser.format_http_date exp_time in
900920 Buffer.add_string buffer (Printf.sprintf "; Expires=%s" exp_str))
901921 (expires cookie);
902922
+2-3
lib/core/cookeio.mli
···527527 Includes all cookie attributes: Max-Age, Expires, Domain, Path, Secure,
528528 HttpOnly, Partitioned, and SameSite.
529529530530- Note: The Expires attribute is currently formatted using RFC 3339 format,
531531- which differs from the RFC-recommended rfc1123-date format specified in
532532- {{:https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1} Section 4.1.1}.
530530+ The Expires attribute uses rfc1123-date format ("Sun, 06 Nov 1994 08:49:37 GMT")
531531+ as specified in {{:https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1} Section 4.1.1}.
533532534533 @see <https://datatracker.ietf.org/doc/html/rfc6265#section-4.1> RFC 6265 Section 4.1 - The Set-Cookie Header *)
535534