diff options
author | Marc Coquand <marcc@fastmail.fr> | 2023-12-02 13:08:13 -0600 |
---|---|---|
committer | Marc Coquand <marcc@fastmail.fr> | 2023-12-02 13:08:13 -0600 |
commit | 11d14f6dd8581715e5241f1fc780a14bf4cc40a2 (patch) | |
tree | 32d20403bd99b766a2c52c90a02726653713c16d /lib/http_date.ml | |
parent | 3fd0ae419ff2dadb0a566a28c042333affbb03b4 (diff) | |
download | wormhole-11d14f6dd8581715e5241f1fc780a14bf4cc40a2.tar.gz wormhole-11d14f6dd8581715e5241f1fc780a14bf4cc40a2.tar.bz2 wormhole-11d14f6dd8581715e5241f1fc780a14bf4cc40a2.zip |
Add initial auth
Diffstat (limited to '')
-rw-r--r-- | lib/http_date.ml | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/http_date.ml b/lib/http_date.ml new file mode 100644 index 0000000..88692a5 --- /dev/null +++ b/lib/http_date.ml @@ -0,0 +1,33 @@ +(* Taken from https://github.com/gopiandcode/ocamlot *) +let parse_date = Parser.parse_date +let parse_date_exn = Parser.parse_date_exn + +let to_utc_string t = + let www = + Ptime.weekday t |> function + | `Sat -> "Sat" + | `Fri -> "Fri" + | `Mon -> "Mon" + | `Wed -> "Wed" + | `Sun -> "Sun" + | `Tue -> "Tue" + | `Thu -> "Thu" + in + let (yyyy, mmm, dd), ((hh, mm, ss), _) = Ptime.to_date_time t in + let mmm = + match mmm with + | 1 -> "Jan" + | 2 -> "Feb" + | 3 -> "Mar" + | 4 -> "Apr" + | 5 -> "May" + | 6 -> "Jun" + | 7 -> "Jul" + | 8 -> "Aug" + | 9 -> "Sep" + | 10 -> "Oct" + | 11 -> "Nov" + | 12 -> "Dec" + | _ -> assert false + in + Printf.sprintf "%s, %02d %s %04d %02d:%02d:%02d GMT" www dd mmm yyyy hh mm ss |