File: docker_client.ml

package info (click to toggle)
ocaml-cohttp 6.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,624 kB
  • sloc: ml: 13,107; makefile: 20; sh: 18; javascript: 18
file content (26 lines) | stat: -rw-r--r-- 918 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Switch = Eio.Switch
module Net = Eio.Net
module Stdenv = Eio.Stdenv
module Client = Cohttp_eio.Client
module Response = Http.Response
module Status = Http.Status

let () = Logs.set_reporter (Logs_fmt.reporter ())
and () = Logs.Src.set_level Cohttp_eio.src (Some Debug)

let () =
  Eio_main.run @@ fun env ->
  let client = Client.make ~https:None env#net in
  Eio.Switch.run @@ fun sw ->
  let response, body =
    Client.get client ~sw
    @@ Uri.make ~scheme:"httpunix" ~host:"/var/run/docker.sock" ~path:"/version"
         ()
  in
  let code = response |> Response.status |> Status.to_int in
  Printf.printf "Response code: %d\n" code;
  Printf.printf "Headers: %s\n"
    (response |> Response.headers |> Http.Header.to_string);
  let body = Eio.Buf_read.(of_flow ~max_size:max_int body |> take_all) in
  Printf.printf "Body of length: %d\n" (String.length body);
  print_endline ("Received body\n" ^ body)