Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 7 additions & 9 deletions src/mist/internal/handler.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
Expand Down Expand Up @@ -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)
}
}
}
11 changes: 6 additions & 5 deletions src/mist/internal/http.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
30 changes: 16 additions & 14 deletions src/mist/internal/http2/stream.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down