-
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.
Add eio backend using parsing and serialization from Http and Cohttp.
- Loading branch information
Showing
25 changed files
with
573 additions
and
1,552 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
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,15 @@ | ||
open Cohttp_eio | ||
|
||
let () = Logs.set_reporter (Logs_fmt.reporter ()) | ||
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 | ||
Eio.Switch.run @@ fun sw -> | ||
match Client.get ~sw env#net (Uri.of_string "http://example.com") with | ||
| Result.Ok (resp, body) when Http.Status.compare resp.status `OK = 0 -> | ||
Fmt.string Format.std_formatter | ||
@@ Eio.Buf_read.(take_all @@ of_flow ~max_size:max_int body) | ||
| Result.Ok (resp, _) -> | ||
Fmt.epr "Unexpected HTTP status: %a" Http.Status.pp resp.status | ||
| Result.Error e -> Fmt.epr "HTTP error: %s" e |
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,16 @@ | ||
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 host, port = ("www.example.org", 80) in | ||
let he = Unix.gethostbyname host 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 res = Client.get ~conn ~port env ~host "/" in | ||
Client.read_fixed res |> Result.ok) | ||
Eio.Switch.run @@ fun sw -> | ||
match Client.get env#net ~sw (Uri.of_string "http://www.example.org") with | ||
| Result.Error e -> Result.Error (`Fatal e) | ||
| Result.Ok (_, body) -> | ||
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.