Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eio backend using stock parsing, serialization and signatures from Cohttp. #984

Merged
merged 30 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d9038c8
Add eio backend using parsing and serialization from Http and Cohttp.
mefyl Jun 13, 2023
47ac2d7
Move server generic signature from cohttp-lwt to cohttp.
mefyl Jun 14, 2023
06feafb
cohttp-eio: Honor the server signature from cohttp.
mefyl Jun 16, 2023
ab94910
Extract generic client signature from cohttp-lwt to cohttp, honor it …
mefyl Jun 16, 2023
9533819
Apply suggestions from code review
mefyl Jun 19, 2023
535334b
cohttp-eio.Server: Make connection the peer address, not the socket i…
mefyl Jun 16, 2023
cf88655
cohttp-eio.Server: Send a bad request response in case of client error.
mefyl Jun 16, 2023
8b7d57a
Do not link libraries with `eio.mock`.
mefyl Jun 19, 2023
7a12cdd
cohttp-eio: Make example multi-domain proof.
mefyl Jun 19, 2023
e06abd4
cohttp-eio: Accept `\n` without `\r` as a line terminator.
mefyl Jun 19, 2023
87e50fa
cohttp-eio: Simplify `Server.run`.
mefyl Jun 19, 2023
59b19ca
Do not omit null content-length headers.
mefyl Jun 15, 2023
8151742
Run eio tests only for cohttp-eio package.
mefyl Jun 30, 2023
2ea9669
Add missing log.threaded library to eio examples.
mefyl Jun 30, 2023
cbc1a7d
Fix rebase.
mefyl Jun 30, 2023
6319289
cohttp-eio: Expose IO.
adatario Jun 30, 2023
fb5a55b
cohttp-eio: Pass a switch to the request callback.
mefyl Jul 19, 2023
09ff049
cohttp-eio: Expose more options from `run_server`.
mefyl Jul 19, 2023
bd3a672
Merge master into eio.
mefyl Jul 20, 2023
3bd95ac
Merge master into eio.
mefyl Aug 17, 2023
882bbce
Update to Eio 0.12
talex5 Sep 1, 2023
f957e4d
cohttp-eio: require `on_error` argument
talex5 Sep 1, 2023
2a079ad
Merge talex5/eio into mefyl/eio.
mefyl Sep 15, 2023
ada1d0b
Merge branch 'master' into eio
mefyl Sep 27, 2023
1bf3a4f
Changelog: Document new eio implementation.
mefyl Sep 27, 2023
aa82db6
Format.
mefyl Sep 27, 2023
969cda2
Require eio 0.12.
mefyl Sep 27, 2023
7a598e5
update CI workflow
mseri Sep 28, 2023
704538a
Remove upper bound on eio constraint.
mefyl Sep 30, 2023
b8a964f
cohttp-eio: Add missing tests dependencies.
mefyl Sep 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- cohttp-eio: convert to Eio.Buf_read (talex5 #882)
- cohttp lwt client: Connection cache and explicit pipelining (madroach #853)
- http: add Http.Request.make and simplify Http.Response.make (bikallem mseri #878)
- http: add pretty printer functions (bikallem #880)
- http: add pretty printer functions (bikallem #880)
- New eio based client and server on top of the http library (bikallem #857)
- New curl based clients (rgrinberg #813)
+ cohttp-curl-lwt for an Lwt backend
Expand Down Expand Up @@ -111,10 +111,10 @@
+ ```clean_dup``` enables the user to clean headers that follows the {{:https://tools.ietf.org/html/rfc7230#section-3.2.2} RFC7230§3.2.2} (no duplicate, except ```set-cookie```)
+ ```get_multi_concat``` has been added to get a result similar to the previous ```get``` function.

- Cohttp.Header: performance improvement (mseri, anuragsoni #778)
- Cohttp.Header: performance improvement (mseri, anuragsoni #778)
**Breaking** the headers are no-longer lowercased when parsed, the headers key comparison is case insensitive instead.

- cohttp-lwt-unix: Adopt ocaml-conduit 5.0.0 (smorimoto #787)
- cohttp-lwt-unix: Adopt ocaml-conduit 5.0.0 (smorimoto #787)
**Breaking** `Conduit_lwt_unix.connect`'s `ctx` param type chaged from `ctx` to `ctx Lazy.t`

- cohttp-mirage: fix deprecated fmt usage (tmcgilchrist #783)
Expand Down
1 change: 1 addition & 0 deletions cohttp-eio.opam
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bug-reports: "https://github.com/mirage/ocaml-cohttp/issues"
depends: [
"dune" {>= "3.0"}
"base-domains"
"cohttp" {= version}
"eio" {>= "0.10"}
"eio_main" {with-test}
"mdx" {with-test}
Expand Down
17 changes: 15 additions & 2 deletions cohttp-eio/examples/client1.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
open Cohttp_eio

let () = Logs.set_reporter (Logs_fmt.reporter ())
mefyl marked this conversation as resolved.
Show resolved Hide resolved

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
Eio.Switch.run @@ fun sw ->
let resp, body =
Client.get ~sw env#net (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
16 changes: 7 additions & 9 deletions cohttp-eio/examples/client_timeout.ml
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.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 env#net ~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@."
19 changes: 12 additions & 7 deletions cohttp-eio/examples/docker_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ module Client = Cohttp_eio.Client
module Response = Http.Response
module Status = Http.Status

let () = Logs.set_reporter (Logs_fmt.reporter ())
and () = Logs.Src.set_level Cohttp_eio.src (Some Debug)

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 ~host:"docker" env "/version" in
let code = fst res |> Response.status |> Status.to_int in
Eio.Switch.run @@ fun sw ->
let response, body =
Client.get env#net ~sw
@@ Uri.make ~scheme:"httpunix" ~host:"/var/run/docker.sock" ~path:"/version"
()
in
let code = response |> 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
(response |> Response.headers |> Http.Header.to_string);
let body = Eio.Buf_read.(of_flow ~max_size:max_int body |> take_all) in
Printf.printf "Body of length: %d\n" (String.length body);
print_endline ("Received body\n" ^ body)
2 changes: 1 addition & 1 deletion cohttp-eio/examples/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executables
(names server1 client1 docker_client client_timeout)
(libraries cohttp-eio eio_main eio.unix unix))
(libraries cohttp-eio eio_main eio.unix fmt unix logs.fmt logs.threaded))

(alias
(name runtest)
Expand Down
28 changes: 19 additions & 9 deletions cohttp-eio/examples/server1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,29 @@ let text =
was coming to, but it was too dark to see anything; then she looked at the \
sides of the well, and noticed that they were filled with cupboards......"

open Cohttp_eio
let () = Logs.set_reporter (Logs_fmt.reporter ())
and () = Logs.Src.set_level Cohttp_eio.src (Some Debug)

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
| _ -> Server.not_found_response
let handler _socket request _body =
match Http.Request.resource request with
| "/" -> (Http.Response.make (), Cohttp_eio.Body.of_string text)
| "/html" ->
( Http.Response.make
~headers:(Http.Header.of_list [ ("content-type", "text/html") ])
(),
(* Use a plain flow to test chunked encoding *)
Eio.Flow.string_source text )
| _ -> (Http.Response.make ~status:`Not_found (), Cohttp_eio.Body.of_string "")

let () =
let port = ref 8080 in
Arg.parse
[ ("-p", Arg.Set_int port, " Listening port number(8080 by default)") ]
ignore "An HTTP/1.1 server";

Eio_main.run @@ fun env -> Server.run ~port:!port env app
Eio_main.run @@ fun env ->
Eio.Switch.run @@ fun sw ->
let socket =
Eio.Net.listen env#net ~sw ~backlog:128 ~reuse_addr:true
(`Tcp (Eio.Net.Ipaddr.V4.loopback, !port))
and server = Cohttp_eio.Server.make ~callback:handler () in
Cohttp_eio.Server.run socket server
Loading
Loading