Skip to content

Commit cf2ae33

Browse files
authored
Merge pull request #1023 from talex5/eio-fix-example
cohttp-eio: Improve error handling in example server
2 parents 6ed9bae + 282c81e commit cf2ae33

File tree

5 files changed

+8
-4
lines changed

5 files changed

+8
-4
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Unreleased
22

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

cohttp-bench/eio_server.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ let headers = Cohttp.Header.of_list [ ("content-length", Int.to_string length) ]
77
let server_callback _conn _req _body =
88
Server.respond_string ~headers ~status:`OK ~body:text ()
99

10-
1110
let () =
1211
let port = ref 8080 in
1312
Arg.parse

cohttp-eio.opam

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ depends: [
2626
"eio" {>= "0.12"}
2727
"eio_main" {with-test}
2828
"mdx" {with-test}
29-
"uri" {with-test}
29+
"logs"
30+
"uri"
3031
"tls-eio" {with-test & >= "0.17.2"}
3132
"mirage-crypto-rng-eio" {with-test & >= "0.11.2"}
3233
"fmt"

cohttp-eio/examples/server1.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ let handler _socket request _body =
4242
Eio.Flow.string_source text )
4343
| _ -> (Http.Response.make ~status:`Not_found (), Cohttp_eio.Body.of_string "")
4444

45+
let log_warning ex = Logs.warn (fun f -> f "%a" Eio.Exn.pp ex)
46+
4547
let () =
4648
let port = ref 8080 in
4749
Arg.parse
@@ -53,4 +55,4 @@ let () =
5355
Eio.Net.listen env#net ~sw ~backlog:128 ~reuse_addr:true
5456
(`Tcp (Eio.Net.Ipaddr.V4.loopback, !port))
5557
and server = Cohttp_eio.Server.make ~callback:handler () in
56-
Cohttp_eio.Server.run socket server ~on_error:raise
58+
Cohttp_eio.Server.run socket server ~on_error:log_warning

dune-project

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,8 @@
375375
(>= 0.12))
376376
(eio_main :with-test)
377377
(mdx :with-test)
378-
(uri :with-test)
378+
logs
379+
uri
379380
(tls-eio (and :with-test (>= 0.17.2)))
380381
(mirage-crypto-rng-eio (and :with-test (>= 0.11.2)))
381382
fmt

0 commit comments

Comments
 (0)