-
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.
eio(client): use Eio.Flow.two_way in call()
- Loading branch information
Showing
8 changed files
with
48 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
open Eio | ||
open Cohttp_eio | ||
|
||
let connect_info url = | ||
let connect_info env sw url = | ||
let uri = Uri.of_string url in | ||
let host = Uri.host uri |> Option.get in | ||
let port = Uri.port uri |> Option.value ~default:80 in | ||
let path = Uri.of_string (Uri.path uri) in | ||
let addr = | ||
let path = Uri.path uri in | ||
let flow = | ||
let he = Unix.gethostbyname host in | ||
he.h_addr_list.(0) | ||
let addr = `Tcp (Eio_unix.Ipaddr.of_unix he.h_addr_list.(0), port) in | ||
(Net.connect ~sw (Stdenv.net env) addr :> Eio.Flow.two_way) | ||
in | ||
(Eio_unix.Ipaddr.of_unix addr, port, path) | ||
(flow, path) | ||
|
||
let () = | ||
Eio_main.run @@ fun env -> | ||
Switch.run @@ fun sw -> | ||
let addr, port, path = connect_info "http://www.reddit.com/" in | ||
let flow, _path = connect_info env sw "http://www.example.org/" in | ||
let res = | ||
Client.get | ||
~headers:(Http.Header.of_list [ ("Accept", "application/json") ]) | ||
env sw | ||
(`Tcp (addr, port)) | ||
path | ||
~headers:(Http.Header.of_list [ ("Host", "www.example.org") ]) | ||
sw flow "/" | ||
in | ||
match Client.read_fixed res with Some b -> print_string b | None -> () |
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,4 +1,4 @@ | ||
(library | ||
(name cohttp_eio) | ||
(public_name cohttp-eio) | ||
(libraries eio cstruct http bigstringaf fmt uri)) | ||
(libraries eio cstruct http bigstringaf fmt)) |
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