From 57d45e2bb64189512cde6c514f1c1cec8e0caa62 Mon Sep 17 00:00:00 2001 From: Giacomo Cavalieri Date: Mon, 3 Nov 2025 11:33:21 +0100 Subject: [PATCH] remove deprecated unwrap both --- CHANGELOG.md | 4 ++++ src/mist/internal/handler.gleam | 16 +++++++-------- src/mist/internal/http.gleam | 11 +++++----- src/mist/internal/http2/stream.gleam | 30 +++++++++++++++------------- 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b97ac5d..b275234 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +# Unreleased + +- Removed usage of deprecated `result.unwrap_both` + # v5.0.3 - Replace custom `rescue` with the `exception` package - Bump `gramps` version for better WebSocket compression support diff --git a/src/mist/internal/handler.gleam b/src/mist/internal/handler.gleam index ac746ba..4329da1 100644 --- a/src/mist/internal/handler.gleam +++ b/src/mist/internal/handler.gleam @@ -48,7 +48,7 @@ pub fn with_func(handler: Handler) -> Loop(State, SendMessage) { transport: conn.transport, ) - case msg, state { + let result = case msg, state { User(Send(..)), Http1(..) -> { Error(Error("Attempted to send HTTP/2 response without upgrade")) } @@ -116,13 +116,11 @@ pub fn with_func(handler: Handler) -> Loop(State, SendMessage) { |> result.map(Http2) } } - |> result.map(glisten.continue) - |> result.map_error(fn(err) { - case err { - Ok(_nil) -> glisten.stop() - Error(reason) -> glisten.stop_abnormal(reason) - } - }) - |> result.unwrap_both + + case result { + Ok(value) -> glisten.continue(value) + Error(Ok(_nil)) -> glisten.stop() + Error(Error(reason)) -> glisten.stop_abnormal(reason) + } } } diff --git a/src/mist/internal/http.gleam b/src/mist/internal/http.gleam index 12247df..8744e53 100644 --- a/src/mist/internal/http.gleam +++ b/src/mist/internal/http.gleam @@ -316,15 +316,16 @@ pub fn parse_request( host_header |> string.split_once(":") |> result.unwrap(#(host_header, "")) - let port = - int.parse(port) - |> result.map_error(fn(_err) { + + let port = case int.parse(port) { + Ok(port) -> port + Error(_) -> case scheme { http.Https -> 443 http.Http -> 80 } - }) - |> result.unwrap_both + } + let req = request.Request( body: Connection(..conn, body: Initial(rest)), diff --git a/src/mist/internal/http2/stream.gleam b/src/mist/internal/http2/stream.gleam index 74b1f92..59dc72c 100644 --- a/src/mist/internal/http2/stream.gleam +++ b/src/mist/internal/http2/stream.gleam @@ -94,20 +94,22 @@ pub fn new( ), ) - request.new() - |> request.set_body(conn) - |> make_request(headers, _) - |> result.map(handler) - |> result.map(fn(resp) { - process.send(state.data_subject, Done) - actor.continue(InternalState(..state, pending_response: Some(resp))) - }) - |> result.map_error(fn(err) { - actor.stop_abnormal( - "Failed to respond to request: " <> string.inspect(err), - ) - }) - |> result.unwrap_both + let result = + request.new() + |> request.set_body(conn) + |> make_request(headers, _) + + case result { + Ok(value) -> { + let resp = handler(value) + process.send(state.data_subject, Done) + actor.continue(InternalState(..state, pending_response: Some(resp))) + } + Error(err) -> + actor.stop_abnormal( + "Failed to respond to request: " <> string.inspect(err), + ) + } } Done, True -> { let assert Some(resp) = state.pending_response