-
Notifications
You must be signed in to change notification settings - Fork 176
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 #984 from mefyl/eio
Eio backend using stock parsing, serialization and signatures from Cohttp.
- Loading branch information
Showing
37 changed files
with
870 additions
and
1,728 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 |
---|---|---|
|
@@ -120,6 +120,7 @@ jobs: | |
local-packages: | ||
- | | ||
http.opam | ||
cohttp.opam | ||
cohttp-eio.opam | ||
runs-on: ${{ matrix.os }} | ||
|
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 |
---|---|---|
@@ -1,6 +1,18 @@ | ||
open Cohttp_eio | ||
|
||
let () = Logs.set_reporter (Logs_fmt.reporter ()) | ||
|
||
and () = | ||
(* The eio backend does not leverage domains yet, but might in the near future *) | ||
Logs_threaded.enable () | ||
|
||
and () = Logs.Src.set_level Cohttp_eio.src (Some Debug) | ||
|
||
let () = | ||
Eio_main.run @@ fun env -> | ||
let res = Client.get env ~host:"www.example.org" "/" in | ||
print_string @@ Client.read_fixed res | ||
let client = Client.make env#net in | ||
Eio.Switch.run @@ fun sw -> | ||
let resp, body = Client.get ~sw client (Uri.of_string "http://example.com") in | ||
if Http.Status.compare resp.status `OK = 0 then | ||
print_string @@ Eio.Buf_read.(parse_exn take_all) body ~max_size:max_int | ||
else Fmt.epr "Unexpected HTTP status: %a" Http.Status.pp resp.status |
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,18 +1,17 @@ | ||
open Eio | ||
open Cohttp_eio | ||
|
||
let () = | ||
Eio_main.run @@ fun env -> | ||
Switch.run @@ fun sw -> | ||
let client = Client.make env#net in | ||
(* Increment/decrement this value to see success/failure. *) | ||
let timeout_s = 0.01 in | ||
Eio.Time.with_timeout env#clock timeout_s (fun () -> | ||
let host, port = ("www.example.org", 80) in | ||
let he = Unix.gethostbyname host in | ||
let addr = `Tcp (Eio_unix.Net.Ipaddr.of_unix he.h_addr_list.(0), port) in | ||
let conn = Net.connect ~sw env#net addr in | ||
let res = Client.get ~conn ~port env ~host "/" in | ||
Client.read_fixed res |> Result.ok) | ||
Eio.Switch.run @@ fun sw -> | ||
let _, body = | ||
Client.get client ~sw (Uri.of_string "http://www.example.org") | ||
in | ||
Eio.Buf_read.(of_flow ~max_size:max_int body |> take_all) |> Result.ok) | ||
|> function | ||
| Ok s -> print_string s | ||
| Error `Timeout -> print_string "Connection timed out" | ||
| Error (`Fatal e) -> Fmt.epr "fatal error: %s@." e | ||
| Error `Timeout -> Fmt.epr "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
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.