Skip to content

Commit

Permalink
cohttp-eio: Use system authenticator in example
Browse files Browse the repository at this point in the history
  • Loading branch information
talex5 committed Oct 2, 2024
1 parent a79b684 commit bf986f2
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 4 deletions.
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: Use system authenticator in example.
- http, cohttp: remove the scheme field from requests. This means that
[Request.uri] no longer returns the same URI as was to create the request
with [Request.make] (@rgrinberg 1086)
Expand Down
1 change: 1 addition & 0 deletions cohttp-eio.opam
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ depends: [
"uri"
"tls-eio" {with-test & >= "1.0.0"}
"mirage-crypto-rng-eio" {with-test & >= "0.11.2"}
"ca-certs" {with-test & >= "1.0.0"}
"fmt"
"ptime"
"http" {= version}
Expand Down
10 changes: 6 additions & 4 deletions cohttp-eio/examples/client_tls.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
open Cohttp_eio

let authenticator =
match Ca_certs.authenticator () with
| Ok x -> x
| Error (`Msg m) -> Fmt.failwith "Failed to create system store X509 authenticator: %s" m

let () =
Logs.set_reporter (Logs_fmt.reporter ());
Logs_threaded.enable ();
Logs.Src.set_level Cohttp_eio.src (Some Debug)

let null_auth ?ip:_ ~host:_ _ =
Ok None (* Warning: use a real authenticator in your code! *)

let https ~authenticator =
let tls_config =
match Tls.Config.client ~authenticator () with
Expand All @@ -25,7 +27,7 @@ let () =
Eio_main.run @@ fun env ->
Mirage_crypto_rng_eio.run (module Mirage_crypto_rng.Fortuna) env @@ fun () ->
let client =
Client.make ~https:(Some (https ~authenticator:null_auth)) env#net
Client.make ~https:(Some (https ~authenticator)) env#net
in
Eio.Switch.run @@ fun sw ->
let resp, body =
Expand Down
1 change: 1 addition & 0 deletions cohttp-eio/examples/dune
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
logs.fmt
logs.threaded
tls-eio
ca-certs
mirage-crypto-rng-eio))

(alias
Expand Down
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@
uri
(tls-eio (and :with-test (>= 1.0.0)))
(mirage-crypto-rng-eio (and :with-test (>= 0.11.2)))
(ca-certs (and :with-test (>= "1.0.0")))
fmt
ptime
(http
Expand Down

0 comments on commit bf986f2

Please sign in to comment.