Skip to content

Commit

Permalink
Merge pull request #1023 from talex5/eio-fix-example
Browse files Browse the repository at this point in the history
cohttp-eio: Improve error handling in example server
  • Loading branch information
mseri committed Feb 27, 2024
2 parents 6ed9bae + 282c81e commit cf2ae33
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
@@ -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
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
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
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
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

0 comments on commit cf2ae33

Please sign in to comment.