-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #879 from bikallem/eio-client
cohttp-eio Client module
- Loading branch information
Showing
26 changed files
with
842 additions
and
343 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
version=0.21.0 | ||
profile=conventional | ||
break-infix=fit-or-vertical | ||
parse-docstrings=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
open Eio | ||
open Cohttp_eio | ||
|
||
let () = | ||
Eio_main.run @@ fun env -> | ||
Switch.run @@ fun sw -> | ||
let hostname, port = ("www.example.org", 80) in | ||
let he = Unix.gethostbyname hostname in | ||
let addr = `Tcp (Eio_unix.Ipaddr.of_unix he.h_addr_list.(0), port) in | ||
let conn = Net.connect ~sw env#net addr in | ||
let host = (hostname, Some port) in | ||
let res = Client.get ~conn host "/" in | ||
print_string @@ Client.read_fixed res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
open Eio | ||
open Cohttp_eio | ||
|
||
let () = | ||
Eio_main.run @@ fun env -> | ||
Switch.run @@ fun sw -> | ||
(* Increment/decrement this value to see success/failure. *) | ||
let timeout_s = 0.01 in | ||
Eio.Time.with_timeout env#clock timeout_s (fun () -> | ||
let hostname, port = ("www.example.org", 80) in | ||
let he = Unix.gethostbyname hostname in | ||
let addr = `Tcp (Eio_unix.Ipaddr.of_unix he.h_addr_list.(0), port) in | ||
let conn = Net.connect ~sw env#net addr in | ||
let host = (hostname, Some port) in | ||
let res = Client.get ~conn host "/" in | ||
Client.read_fixed res |> Result.ok) | ||
|> function | ||
| Ok s -> print_string s | ||
| Error `Timeout -> print_string "Connection timed out" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
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 () = | ||
Eio_main.run @@ fun env -> | ||
Switch.run @@ fun sw -> | ||
let addr = `Unix "/var/run/docker.sock" in | ||
let conn = Net.connect ~sw env#net addr in | ||
let res = Client.get ~conn ("docker", None) "/version" in | ||
let code = fst res |> Response.status |> Status.to_int in | ||
Printf.printf "Response code: %d\n" code; | ||
Printf.printf "Headers: %s\n" | ||
(fst res |> Response.headers |> Http.Header.to_string); | ||
let body = Client.read_fixed res in | ||
Printf.printf "Body of length: %d\n" (String.length body); | ||
print_endline ("Received body\n" ^ body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.