Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cohttp-eio: Improve error handling in example server #1023

Merged
merged 2 commits into from
Feb 27, 2024
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Unreleased

- cohttp-eio: Improve error handling in example server (talex5 #1023)
- cohttp-eio: Don't blow up `Server.callback` on client disconnections. (mefyl #1015)
- http: Fix assertion in `Source.to_string_trim` when `pos <> 0` (mefyl #1017)

Expand Down
1 change: 0 additions & 1 deletion cohttp-bench/eio_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ let headers = Cohttp.Header.of_list [ ("content-length", Int.to_string length) ]
let server_callback _conn _req _body =
Server.respond_string ~headers ~status:`OK ~body:text ()


let () =
let port = ref 8080 in
Arg.parse
Expand Down
3 changes: 2 additions & 1 deletion cohttp-eio.opam
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ depends: [
"eio" {>= "0.12"}
"eio_main" {with-test}
"mdx" {with-test}
"uri" {with-test}
"logs"
"uri"
"tls-eio" {with-test & >= "0.17.2"}
"mirage-crypto-rng-eio" {with-test & >= "0.11.2"}
"fmt"
Expand Down
4 changes: 3 additions & 1 deletion cohttp-eio/examples/server1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ let handler _socket request _body =
Eio.Flow.string_source text )
| _ -> (Http.Response.make ~status:`Not_found (), Cohttp_eio.Body.of_string "")

let log_warning ex = Logs.warn (fun f -> f "%a" Eio.Exn.pp ex)

let () =
let port = ref 8080 in
Arg.parse
Expand All @@ -53,4 +55,4 @@ let () =
Eio.Net.listen env#net ~sw ~backlog:128 ~reuse_addr:true
(`Tcp (Eio.Net.Ipaddr.V4.loopback, !port))
and server = Cohttp_eio.Server.make ~callback:handler () in
Cohttp_eio.Server.run socket server ~on_error:raise
Cohttp_eio.Server.run socket server ~on_error:log_warning
3 changes: 2 additions & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@
(>= 0.12))
(eio_main :with-test)
(mdx :with-test)
(uri :with-test)
logs
uri
(tls-eio (and :with-test (>= 0.17.2)))
(mirage-crypto-rng-eio (and :with-test (>= 0.11.2)))
fmt
Expand Down
Loading