Skip to content

Commit

Permalink
cohttp-eio(examples): update client and server example (#957)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcello Seri <[email protected]>
  • Loading branch information
bikallem and mseri authored Dec 21, 2022
1 parent 09fcce2 commit 72fe9fc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Upgrade dune to v3.0 (bikallem #947)
- cohttp-eio: allow client to optionally configure request pipelining (bikallem #949)
- cohttp-eio: update to Eio 0.7 (talex5 #952)
- cohttp-eio: update examples to use eio 0.7 primitives (bikallem #?)
- cohttp-eio: generate Date header in responses (bikallem #955)

## v6.0.0~alpha0 (2022-10-24)
Expand Down
15 changes: 6 additions & 9 deletions cohttp-eio/examples/client1.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
open Eio
open Cohttp_eio

let () =
let host, port = ("www.example.org", 80) in
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
Eio.Net.with_tcp_connect ~host ~service:(string_of_int port) env#net
(fun conn ->
let host = (host, Some port) in
let res = Client.get ~conn host "/" in
print_string @@ Client.read_fixed res)
3 changes: 2 additions & 1 deletion cohttp-eio/examples/server1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ let text =

open Cohttp_eio

let app (req, _reader, _client_addr) =
let app : Server.request -> Server.response =
fun ((req, _, _) : Server.request) ->
match Http.Request.resource req with
| "/" -> Server.text_response text
| "/html" -> Server.html_response text
Expand Down

0 comments on commit 72fe9fc

Please sign in to comment.