From a70e59463f743830f64f743f8b6c081794b4eaaf Mon Sep 17 00:00:00 2001 From: Clombrong Date: Sun, 29 Jun 2025 20:51:22 +0200 Subject: refactor(stream): migrate indifferent features to own function --- lib/stream.ml | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/stream.ml b/lib/stream.ml index cbc8a16..451f9b5 100644 --- a/lib/stream.ml +++ b/lib/stream.ml @@ -89,13 +89,16 @@ let negotiate feature portal {starttls; sasl; _} : unit Lwt.t = | Error err -> Lwt.fail_with (parse_auth_error err) | Ok _ -> print_endline "Success!"; Lwt.return_unit else Lwt.fail InsufficientEncryption - in let open Feature in - match feature with - | Mandatory STARTTLS -> Starttls.upgrade portal - | Optional STARTTLS -> if starttls.prefer_starttls - then Starttls.upgrade portal - else Lwt.return_unit - | f -> - match unwrap f with - | Mechanisms mechs -> authenticate mechs - | _ -> Lwt.return_unit + in + let open Feature in + (* Most features don't care about whether they're mandatory or optional. *) + let indifferent = function + | Mechanisms mechs -> authenticate mechs + | _ -> Lwt.return_unit + in + match feature with + | Mandatory STARTTLS -> Starttls.upgrade portal + | Optional STARTTLS -> if starttls.prefer_starttls + then Starttls.upgrade portal + else Lwt.return_unit + | f -> unwrap f |> indifferent -- cgit v1.2.3