package https-eio

  1. Overview
  2. Docs
Authenticated HTTPS client wrapper and shared request helper for Eio

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.1.tar.gz
md5=b502659cffd9e9bc71d748ce9c512644
sha512=8db8541e2b82fcc58439d9db543b32548f44ee05fd1cf091931da87877f87b96a3d2fd67cd63150b512c501456d0d5d14b8b4d27790535585f28c48d8646868b

Description

Builds the Uri.t -> flow -> Tls_eio.t wrapper that cohttp-eio's client expects for its ~https hook: system CA bundle detection (via ca-certs), a Tls.Config.client, and the one-time Mirage_crypto_rng seed that TLS handshake needs before it can generate any key/nonce material. Extracted from four independent, byte-identical copies of this code (aws-eio's Aws_tls, obs-loki-eio's Obs_loki_tls, obs-prometheus-eio's Obs_prometheus_tls, and Sun's in-tree Kafka_service_tls) after an unseeded-RNG bug had to be hand-ported across all four.

Also exposes request: a timeout-bounded, TLS-wrapped HTTP request built on cohttp-eio, factored out after obs-loki-eio, obs-prometheus-eio, kafka-eio-service, and sun-svc's JWKS fetch each independently rebuilt the same plumbing (validate URL, connect, apply ~https, send, read a bounded response body, classify timeout/network failures) on top of this package's own TLS wrapper. Not a general-purpose HTTP client — no retries, no connection pooling, no redirect handling; callers that need SigV4 byte-fidelity (aws-eio) or connection reuse still build their own transport.

Added to opam-repository:

README

https-eio

Authenticated HTTPS client wrapper for Eio — the Uri.t -> flow -> Tls_eio.t function cohttp-eio's client expects for its ~https hook — plus request, a shared timeout-bounded HTTP request helper built on top of it.

https_for_uri does exactly three things:

  • Detects the system CA trust store via ca-certs (no hand-rolled, platform-specific path list).
  • Builds a Tls.Config.client from that trust store.
  • Seeds Mirage_crypto_rng before the first real handshake and caches the built wrapper, domain-safely (double-checked locking over an Atomic.t, not a bare Stdlib.Lazy.t — see lib/https_eio.ml for why).

Extracted after the same ~90 lines were found duplicated, byte-for-byte, across four packages (aws-eio, obs-loki-eio, obs-prometheus-eio, and Sun's in-tree kafka-eio-service) — see CHANGES.md. There's no separate published opam library for this; cohttp-eio's own repo ships the same pattern as example code (cohttp-eio/examples/client_tls.ml) rather than a reusable package.

request was extracted later, for the same reason: obs-loki-eio, obs-prometheus-eio, kafka-eio-service, and sun-svc's JWKS fetch had each independently rebuilt "validate a URL, connect with https_for_uri's wrapper, send one request, read a bounded response body, classify timeout/network failures" on top of this package's own TLS layer. Not a general-purpose HTTP client — no retries, no connection pooling (a fresh connection per call), no redirect handling. aws-eio is the deliberate exception that still builds its own transport, for SigV4 byte-fidelity reasons documented in its own README.

Usage

Eio_main.run @@ fun env ->
match Https_eio.https_for_uri (Uri.of_string "https://example.com") with
| Error e -> failwith (Https_eio.error_to_string e)
| Ok https ->
  let client = Cohttp_eio.Client.make ~https env#net in
  ...
Eio_main.run @@ fun env ->
match Https_eio.request ~net:env#net ~clock:env#clock ~meth:`GET
        ~url:"https://example.com/status" () with
| Ok (status, body) -> Printf.printf "%d: %s\n" status body
| Error e -> failwith (Https_eio.request_error_to_string e)

Build

eval $(opam env)
dune build

Test

dune runtest

No external infrastructure required — the handshake test spins up a local self-signed TLS server (fixtures in test/tls_fixtures/, not trusted by the system CA bundle) and asserts the handshake fails on certificate trust, not on an unseeded RNG.

Dependencies (11)

  1. domain-name >= "0.5.0"
  2. ca-certs >= "1.0.1"
  3. x509 >= "1.0.0"
  4. mirage-crypto-rng >= "2.1.0"
  5. tls-eio >= "2.1.0"
  6. cohttp-eio >= "6.2.0"
  7. http >= "6.0.0"
  8. uri >= "4.4.0"
  9. eio >= "1.3"
  10. ocaml >= "5.4.0"
  11. dune >= "3.0"

Dev Dependencies (3)

  1. odoc with-doc
  2. alcotest with-test
  3. eio_main >= "1.3" & with-test

Conflicts

None