aboutsummaryrefslogtreecommitdiff
path: root/lib/stream.ml
diff options
context:
space:
mode:
authorClombrong <cromblong@egregore.fun>2025-06-29 20:51:22 +0200
committerClombrong <cromblong@egregore.fun>2025-06-29 20:51:22 +0200
commita70e59463f743830f64f743f8b6c081794b4eaaf (patch)
treed49c9fa22afd0d5796e310dd24f14981accff665 /lib/stream.ml
parentc090fa105c47a01a0dc1123174f6deaa5dc5ff29 (diff)
refactor(stream): migrate indifferent features to own function
Diffstat (limited to 'lib/stream.ml')
-rw-r--r--lib/stream.ml23
1 files 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