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

Conduit 3.0.0 #692

Merged
merged 47 commits into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
19b453a
Rename conduit's ctx to resolvers into Cohttp_lwt.Client
dinosaure May 6, 2020
9ab3835
Rename conduit's ctx to resolvers into Cohttp_lwt_jsoo
dinosaure May 6, 2020
e5db383
Update interface and rename conduit's ctx to resolvers
dinosaure May 6, 2020
b98a7a5
Update type of connection for Cohttp_lwt_unix.Io
dinosaure Sep 8, 2020
5d2bb1c
Update Cohttp_lwt_unix.Client with new interface given by Cohttp_lwt.S
dinosaure May 6, 2020
e3d2279
Update implementation of Cohttp_lwt_unix.Net with new version of cond…
dinosaure May 6, 2020
236e5e3
Update Cohttp_lwt_unix.Server with the new way to initialize a server
dinosaure May 6, 2020
6a59953
Update binaries provided by cohttp-lwt-unix
dinosaure May 6, 2020
3242816
Update Cohttp_mirage.Client with the new interface fiven by Cohttp_lwt.S
dinosaure May 6, 2020
181f9c8
Update Cohttp_mirage.Server_with_conduit with the new way to initiali…
dinosaure May 6, 2020
83bf0c2
Update Cohttp_async.Client (rename ssl_config to ssl_ctx) with condui…
dinosaure May 6, 2020
559ac0e
Update Cohttp_async.Server with the new way to initialize a server
dinosaure May 6, 2020
c20c68c
Update binaries provided by cohttp-async
dinosaure May 6, 2020
6075484
Update cohttp-lwt-unix tests (avoid overlap of ports used and use loc…
dinosaure May 6, 2020
b6afe08
Update cohttp-async tests (avoid overlap of ports used and use localh…
dinosaure May 6, 2020
c1e43a1
Add a resolver to run tests on cohttp-lwt-unix
dinosaure May 6, 2020
2cef3c5
Fixes examples with cohttp-async to be able to compile the project
dinosaure May 6, 2020
f9fbaf7
Update to dune.2.0 and apply dune @fmt on dune files
dinosaure May 6, 2020
d5de3bf
Delete Travis CI script (use ocaml-ci instead)
dinosaure May 6, 2020
b6efc31
Update OPAM packages
dinosaure May 6, 2020
3bbdf30
Delay the initialization of the cohttp server
dinosaure Sep 8, 2020
d3e04f0
Be able to resolve *:80 and *:443 domains with cohttp-lwt-unix
dinosaure Sep 8, 2020
32dce1b
Remove unused value sexp_of_ctx
dinosaure Sep 8, 2020
11dc50b
Add an .ocamlformat file
dinosaure Sep 8, 2020
253140c
Create 2 new packages: cohttp-lwt-unix-{ssl,tls} and rename the packa…
dinosaure Sep 21, 2020
ce3fc30
Revert "Create 2 new packages: cohttp-lwt-unix-{ssl,tls} and rename t…
dinosaure Sep 23, 2020
f3a4fe0
Use conduit-lwt-tls to provide a TLS connection with cohttp-lwt-unix …
dinosaure Sep 23, 2020
2f346f1
Rename resolvers to ctx
dinosaure Sep 23, 2020
dfcc589
Net.ctx is sexpable
dinosaure Sep 23, 2020
2e74d83
Use conduit-lwt-tls instead conduit-lwt-ssl in binaries
dinosaure Sep 23, 2020
10ce452
Delete lwt_ssl as a dependency of cohttp-lwt-unix (we use ocaml-tls i…
dinosaure Sep 23, 2020
0a8c31a
Use the last version of conduit (new concrete endpoint)
dinosaure Oct 2, 2020
e97c646
Fix flaky tests on async
dinosaure Oct 2, 2020
7f0efc6
Fix the documentation on cohttp-async
dinosaure Oct 2, 2020
a21c9c6
conduit-lwt-tls is responsible to initialize the PRNG, not cohttp-lwt…
hannesm Oct 4, 2020
f0400d6
cohttp-lwt-unix: allow passing a custom tls_config
hannesm Oct 4, 2020
3f7032e
cohttp-lwt
hannesm Oct 4, 2020
6b0335d
Fix tests about previous renaming of Net module
dinosaure Oct 5, 2020
f206d67
Correctly handle ports from the given Uri.t
dinosaure Oct 5, 2020
fc39c98
Apply dune @fmt
dinosaure Oct 5, 2020
0221253
Delete Cohttp_lwt_unix.Net.init and custom_ctx, the real default ctx …
dinosaure Oct 12, 2020
8443def
cohttp-lwt-unix: use ca-certs, authenticate client connections
hannesm Oct 12, 2020
8267d23
Merge remote-tracking branch 'hannesm/cohttp-lwt-unix-trust-anchors' …
dinosaure Oct 13, 2020
7d56281
Handle peer name when we can on TLS connection
dinosaure Oct 13, 2020
8bd204d
Add cohttp-lwt-unix-nossl and cohttp-lwt-unix-ssl (update cohttp-lwt-…
dinosaure Oct 14, 2020
52d5d58
Update OPAM files
dinosaure Oct 14, 2020
f4d0b68
Remove pin-depends and use conduit.3.0.0
dinosaure Oct 21, 2020
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
Empty file added .gitmodules
Empty file.
2 changes: 2 additions & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = 0.15.0
disable = true
35 changes: 0 additions & 35 deletions .travis.yml

This file was deleted.

8 changes: 8 additions & 0 deletions cohttp-async.opam
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ depends: [
"core" {with-test}
"cohttp" {=version}
"conduit-async" {>="1.2.0"}
"conduit-async-ssl"
"magic-mime"
"logs"
"fmt" {>= "0.8.2"}
Expand All @@ -41,10 +42,17 @@ depends: [
"ounit" {with-test}
"uri" {>= "2.0.0"}
"uri-sexp"
"ipaddr"
]
build: [
["dune" "subst"] {pinned}
["dune" "build" "-p" name "-j" jobs]
["dune" "runtest" "-p" name "-j" jobs] {with-test}
]
dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
pin-depends: [
[ "conduit.dev" "git+https://github.com/mirage/ocaml-conduit.git#8912d458b2f3e43245e99cf3cb74e9c00712a8b0" ]
[ "conduit-tls.dev" "git+https://github.com/mirage/ocaml-conduit.git#8912d458b2f3e43245e99cf3cb74e9c00712a8b0" ]
[ "conduit-async-ssl.dev" "git+https://github.com/mirage/ocaml-conduit.git#8912d458b2f3e43245e99cf3cb74e9c00712a8b0" ]
[ "conduit-async.dev" "git+https://github.com/mirage/ocaml-conduit.git#8912d458b2f3e43245e99cf3cb74e9c00712a8b0" ]
]
19 changes: 12 additions & 7 deletions cohttp-async/bin/cohttp_server_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ let determine_mode cert_file_path key_file_path =
| None, None -> `TCP
| _ -> failwith "Error: must specify both certificate and key for HTTPS"

let start_server docroot port index cert_file key_file verbose () =
let start_server docroot port index cert_file key_file verbose =
(* enable logging to stdout *)
Fmt_tty.setup_std_outputs ();
Logs.set_level @@ if verbose then (Some Logs.Debug) else (Some Logs.Info);
Expand All @@ -116,14 +116,19 @@ let start_server docroot port index cert_file key_file verbose () =
let mode_str = (match mode with `OpenSSL _ -> "HTTPS" | `TCP -> "HTTP") in
Logs.info (fun f -> f "Listening for %s requests on %d" mode_str port);
let info = Printf.sprintf "Served by Cohttp/Async listening on %d" port in
Server.create
~on_handler_error:(`Call (fun addr exn ->
let _never, server = Server.create
~on_handler_error:(`Call (fun flow exn ->
let addr = match Conduit_async.cast flow Conduit_async.TCP.protocol with
| Some flow -> Conduit_async.TCP.Protocol.address flow
| None -> assert false (* XXX(dinosaure): safe when we initialize the server with
[Conduit_async_tcp.service] *) in
Logs.err (fun f -> f "Error from %s" (Socket.Address.to_string addr));
Logs.err (fun f -> f "%s" @@ Exn.to_string exn)))
~mode
(Tcp.Where_to_listen.of_port port)
(handler ~info ~docroot ~index) >>= fun _serv ->
Deferred.never ()
~protocol:Conduit_async.TCP.protocol
~service:Conduit_async.TCP.service
(Conduit_async.TCP.Listen (None, Tcp.Where_to_listen.of_port port))
(handler ~info ~docroot ~index) in
server

let () =
let open Async_command in
Expand Down
10 changes: 5 additions & 5 deletions cohttp-async/bin/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(executables
(names cohttp_curl_async cohttp_server_async)
(package cohttp-async)
(public_names cohttp-curl-async cohttp-server-async)
(libraries cohttp-async async_kernel async.async_command async_unix base
cohttp cohttp_server fmt.tty))
(names cohttp_curl_async cohttp_server_async)
(package cohttp-async)
(public_names cohttp-curl-async cohttp-server-async)
(libraries cohttp-async async_kernel async.async_command async_unix base
cohttp cohttp_server fmt.tty))
89 changes: 54 additions & 35 deletions cohttp-async/src/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,44 @@ module Net = struct
Or_error.return (host, Ipaddr_unix.of_inet_addr addr, port)
| _ -> Or_error.error "Failed to resolve Uri" uri Uri_sexp.sexp_of_t

let connect_uri ?interrupt ?ssl_config uri =
(match Uri.scheme uri with
| Some "httpunix" ->
let connect_uri ?ssl_ctx uri =
match (Uri.scheme uri, ssl_ctx) with
| Some "httpunix", _ ->
let host = Uri.host_with_default ~default:"localhost" uri in
return @@ `Unix_domain_socket host
| _ ->
let tcp_cfg = Conduit_async.TCP.Unix (Socket.Address.Unix.create host) in
Conduit_async.connect tcp_cfg Conduit_async.TCP.protocol
| Some "https", Some ctx ->
lookup uri
|> Deferred.Or_error.ok_exn
>>= fun (_, addr, port) ->
let tcp_cfg =
let addr = Ipaddr_unix.to_inet_addr addr in
Conduit_async.TCP.Inet (Socket.Address.Inet.create addr ~port) in
Conduit_async.connect (ctx, tcp_cfg) Conduit_async_ssl.TCP.protocol
| Some "https", None ->
lookup uri
|> Deferred.Or_error.ok_exn
>>= fun (host, addr, port) ->
return @@ match (Uri.scheme uri, ssl_config) with
| Some "https", Some config ->
`OpenSSL (addr, port, config)
| Some "https", None ->
let config = Conduit_async.V2.Ssl.Config.create ~hostname:host () in
`OpenSSL (addr, port, config)
| _ -> `TCP (addr, port))
>>= fun mode ->
Conduit_async.V2.connect ?interrupt mode
let tcp_cfg =
let addr = Ipaddr_unix.to_inet_addr addr in
Conduit_async.TCP.Inet (Socket.Address.Inet.create addr ~port) in
let ctx = Conduit_async_ssl.context ~hostname:host () in
Conduit_async.connect (ctx, tcp_cfg) Conduit_async_ssl.TCP.protocol
| _ ->
lookup uri
|> Deferred.Or_error.ok_exn
>>= fun (_, addr, port) ->
let tcp_cfg =
let addr = Ipaddr_unix.to_inet_addr addr in
Conduit_async.TCP.Inet (Socket.Address.Inet.create addr ~port) in
Conduit_async.connect tcp_cfg Conduit_async.TCP.protocol

let failwith fmt = Stdlib.Format.kasprintf failwith fmt

let connect_uri ?ssl_ctx uri =
connect_uri ?ssl_ctx uri >>= function
| Ok flow -> Conduit_async.reader_and_writer_of_flow flow
| Error err -> failwith "%a" Conduit_async.pp_error err
end

let read_response ic =
Expand All @@ -65,14 +85,13 @@ let read_response ic =
(res, pipe)
end

let request ?interrupt ?ssl_config ?uri ?(body=`Empty) req =
let request ?ssl_ctx ?uri ?(body=`Empty) req =
(* Connect to the remote side *)
let uri =
match uri with
| Some t -> t
| None -> Request.uri req in
Net.connect_uri ?interrupt ?ssl_config uri
>>= fun (ic, oc) ->
Net.connect_uri ?ssl_ctx uri >>= fun (ic, oc) ->
try_with (fun () ->
Request.write (fun writer ->
Body_raw.write_body Request.write_body body writer) req oc
Expand All @@ -89,10 +108,10 @@ let request ?interrupt ?ssl_config ?uri ?(body=`Empty) req =
raise e
end

let callv ?interrupt ?ssl_config uri reqs =
let callv ?ssl_ctx uri reqs =
let reqs_c = ref 0 in
let resp_c = ref 0 in
Net.connect_uri ?interrupt ?ssl_config uri >>= fun (ic, oc) ->
Net.connect_uri ?ssl_ctx uri >>= fun (ic, oc) ->
try_with (fun () ->
reqs
|> Pipe.iter ~f:(fun (req, body) ->
Expand Down Expand Up @@ -125,7 +144,7 @@ let callv ?interrupt ?ssl_config uri reqs =
raise e
end

let call ?interrupt ?ssl_config ?headers ?(chunked=false) ?(body=`Empty) meth uri =
let call ?ssl_ctx ?headers ?(chunked=false) ?(body=`Empty) meth uri =
(* Create a request, then make the request. Figure out an appropriate
transfer encoding *)
begin
Expand All @@ -140,33 +159,33 @@ let call ?interrupt ?ssl_config ?headers ?(chunked=false) ?(body=`Empty) meth ur
| false -> (* Use chunked encoding if there is a body *)
Request.make_for_client ?headers ~chunked:true meth uri, body
end
end >>= fun (req, body) -> request ?interrupt ?ssl_config ~body ~uri req
end >>= fun (req, body) -> request ?ssl_ctx ~body ~uri req

let get ?interrupt ?ssl_config ?headers uri =
call ?interrupt ?ssl_config ?headers ~chunked:false `GET uri
let get ?ssl_ctx ?headers uri =
call ?ssl_ctx ?headers ~chunked:false `GET uri

let head ?interrupt ?ssl_config ?headers uri =
call ?interrupt ?ssl_config ?headers ~chunked:false `HEAD uri
let head ?ssl_ctx ?headers uri =
call ?ssl_ctx ?headers ~chunked:false `HEAD uri
>>| fun (res, body) ->
(match body with
| `Pipe p -> Pipe.close_read p;
| _ -> ());
res

let post ?interrupt ?ssl_config ?headers ?(chunked=false) ?body uri =
call ?interrupt ?ssl_config ?headers ~chunked ?body `POST uri
let post ?ssl_ctx ?headers ?(chunked=false) ?body uri =
call ?ssl_ctx ?headers ~chunked ?body `POST uri

let post_form ?interrupt ?ssl_config ?headers ~params uri =
let post_form ?ssl_ctx ?headers ~params uri =
let headers = Cohttp.Header.add_opt_unless_exists headers
"content-type" "application/x-www-form-urlencoded" in
let body = Body.of_string (Uri.encoded_of_query params) in
post ?interrupt ?ssl_config ~headers ~chunked:false ~body uri
post ?ssl_ctx ~headers ~chunked:false ~body uri

let put ?interrupt ?ssl_config ?headers ?(chunked=false) ?body uri =
call ?interrupt ?ssl_config ?headers ~chunked ?body `PUT uri
let put ?ssl_ctx ?headers ?(chunked=false) ?body uri =
call ?ssl_ctx ?headers ~chunked ?body `PUT uri

let patch ?interrupt ?ssl_config ?headers ?(chunked=false) ?body uri =
call ?interrupt ?ssl_config ?headers ~chunked ?body `PATCH uri
let patch ?ssl_ctx ?headers ?(chunked=false) ?body uri =
call ?ssl_ctx ?headers ~chunked ?body `PATCH uri

let delete ?interrupt ?ssl_config ?headers ?(chunked=false) ?body uri =
call ?interrupt ?ssl_config ?headers ~chunked ?body `DELETE uri
let delete ?ssl_ctx ?headers ?(chunked=false) ?body uri =
call ?ssl_ctx ?headers ~chunked ?body `DELETE uri
30 changes: 10 additions & 20 deletions cohttp-async/src/client.mli
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
(** Send an HTTP request with an arbitrary body
The request is sent as-is. *)
val request :
?interrupt:unit Async_kernel.Deferred.t ->
?ssl_config:Conduit_async.V2.Ssl.Config.t ->
?ssl_ctx:Conduit_async_ssl.context ->
?uri:Uri.t ->
?body:Body.t ->
Cohttp.Request.t ->
Expand All @@ -11,8 +10,7 @@ val request :
(** Send an HTTP request with arbitrary method and a body
Infers the transfer encoding *)
val call :
?interrupt:unit Async_kernel.Deferred.t ->
?ssl_config:Conduit_async.V2.Ssl.Config.t ->
?ssl_ctx:Conduit_async_ssl.context ->
?headers:Cohttp.Header.t ->
?chunked:bool ->
?body:Body.t ->
Expand All @@ -21,32 +19,28 @@ val call :
(Cohttp.Response.t * Body.t) Async_kernel.Deferred.t

val callv :
?interrupt:unit Async_kernel.Deferred.t ->
?ssl_config:Conduit_async.V2.Ssl.Config.t ->
?ssl_ctx:Conduit_async_ssl.context ->
Uri.t ->
(Cohttp.Request.t * Body.t) Async_kernel.Pipe.Reader.t ->
(Cohttp.Response.t * Body.t) Async_kernel.Pipe.Reader.t Async_kernel.Deferred.t

(** Send an HTTP GET request *)
val get :
?interrupt:unit Async_kernel.Deferred.t ->
?ssl_config:Conduit_async.V2.Ssl.Config.t ->
?ssl_ctx:Conduit_async_ssl.context ->
?headers:Cohttp.Header.t ->
Uri.t ->
(Cohttp.Response.t * Body.t) Async_kernel.Deferred.t

(** Send an HTTP HEAD request *)
val head :
?interrupt:unit Async_kernel.Deferred.t ->
?ssl_config:Conduit_async.V2.Ssl.Config.t ->
?ssl_ctx:Conduit_async_ssl.context ->
?headers:Cohttp.Header.t ->
Uri.t ->
Cohttp.Response.t Async_kernel.Deferred.t

(** Send an HTTP DELETE request *)
val delete :
?interrupt:unit Async_kernel.Deferred.t ->
?ssl_config:Conduit_async.V2.Ssl.Config.t ->
?ssl_ctx:Conduit_async_ssl.context ->
?headers:Cohttp.Header.t ->
?chunked:bool ->
?body:Body.t ->
Expand All @@ -57,8 +51,7 @@ val delete :
[chunked] encoding is off by default as not many servers support it
*)
val post :
?interrupt:unit Async_kernel.Deferred.t ->
?ssl_config:Conduit_async.V2.Ssl.Config.t ->
?ssl_ctx:Conduit_async_ssl.context ->
?headers:Cohttp.Header.t ->
?chunked:bool ->
?body:Body.t ->
Expand All @@ -69,8 +62,7 @@ val post :
[chunked] encoding is off by default as not many servers support it
*)
val put :
?interrupt:unit Async_kernel.Deferred.t ->
?ssl_config:Conduit_async.V2.Ssl.Config.t ->
?ssl_ctx:Conduit_async_ssl.context ->
?headers:Cohttp.Header.t ->
?chunked:bool ->
?body:Body.t ->
Expand All @@ -81,8 +73,7 @@ val put :
[chunked] encoding is off by default as not many servers support it
*)
val patch :
?interrupt:unit Async_kernel.Deferred.t ->
?ssl_config:Conduit_async.V2.Ssl.Config.t ->
?ssl_ctx:Conduit_async_ssl.context ->
?headers:Cohttp.Header.t ->
?chunked:bool ->
?body:Body.t ->
Expand All @@ -91,8 +82,7 @@ val patch :

(** Send an HTTP POST request in form format *)
val post_form:
?interrupt:unit Async_kernel.Deferred.t ->
?ssl_config:Conduit_async.V2.Ssl.Config.t ->
?ssl_ctx:Conduit_async_ssl.context ->
?headers:Cohttp.Header.t ->
params:(string * string list) list ->
Uri.t ->
Expand Down
13 changes: 7 additions & 6 deletions cohttp-async/src/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
(library
(name cohttp_async)
(synopsis "Async backend")
(public_name cohttp-async)
(libraries logs.fmt base fmt async_unix async_kernel uri
uri.services uri-sexp ipaddr.unix conduit-async magic-mime cohttp)
(preprocess (pps ppx_sexp_conv)))
(name cohttp_async)
(synopsis "Async backend")
(public_name cohttp-async)
(libraries logs.fmt base fmt async_unix async_kernel uri uri.services
uri-sexp ipaddr.unix conduit-async conduit-async-ssl magic-mime cohttp)
(preprocess
(pps ppx_sexp_conv)))
Loading