aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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