Skip to content

Commit

Permalink
Merge master into missing-null-content-length.
Browse files Browse the repository at this point in the history
  • Loading branch information
mefyl committed Jun 30, 2023
2 parents d0186f9 + eb2e3b7 commit d5f776c
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 64 deletions.
54 changes: 48 additions & 6 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,62 @@ jobs:
- ocaml-variants.4.11.2+afl
- ocaml-variants.4.12.1+options,ocaml-option-afl
- ocaml-variants.4.13.1+options,ocaml-option-afl
- ocaml-variants.4.14.0+options,ocaml-option-afl
local-packages:
- |
*.opam
!cohttp-eio.opam
!cohttp-curl-async.opam
!cohttp-async.opam
!cohttp-bench.opam
runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
dune-cache: ${{ matrix.os == 'ubuntu-latest' }}
opam-depext: true
opam-depext-flags: --with-test
opam-local-packages: ${{ matrix.local-packages }}

- run: |
sudo apt update
sudo apt upgrade
opam depext conf-libcurl
if: ${{ matrix.os == 'ubuntu-latest' }}
- run: echo "PKG_CONFIG_PATH=$(brew --prefix openssl)/lib/pkgconfig" >>"$GITHUB_ENV"
if: ${{ matrix.os == 'macos-latest' }}

- run: opam install --with-test --deps-only http cohttp cohttp-lwt cohttp-lwt-unix cohttp-server-lwt-unix cohttp-mirage cohttp-curl-lwt cohttp-curl cohttp-top
- run: opam exec -- dune build http cohttp cohttp-lwt cohttp-lwt-unix cohttp-server-lwt-unix cohttp-mirage cohttp-curl-lwt cohttp-curl cohttp-top
- run: opam exec -- dune runtest http cohttp cohttp-lwt cohttp-lwt-unix cohttp-server-lwt-unix cohttp-mirage cohttp-curl-lwt cohttp-curl cohttp-top

build-test-cohttp-async:
if: github.event.pull_request.draft == false
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
ocaml-compiler:
- ocaml-variants.4.14.1+options,ocaml-option-afl
local-packages:
- |
*.opam
!cohttp-eio.opam
runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
Expand All @@ -59,9 +103,9 @@ jobs:
- run: echo "PKG_CONFIG_PATH=$(brew --prefix openssl)/lib/pkgconfig" >>"$GITHUB_ENV"
if: ${{ matrix.os == 'macos-latest' }}

- run: opam install --with-test --deps-only http cohttp cohttp-lwt cohttp-lwt-unix cohttp-server-lwt-unix cohttp-mirage cohttp-async cohttp-curl-async cohttp-curl-lwt cohttp-curl cohttp-top cohttp-bench
- run: opam exec -- dune build http cohttp cohttp-lwt cohttp-lwt-unix cohttp-server-lwt-unix cohttp-mirage cohttp-async cohttp-curl-async cohttp-curl-lwt cohttp-curl cohttp-top cohttp-bench
- run: opam exec -- dune runtest http cohttp cohttp-lwt cohttp-lwt-unix cohttp-server-lwt-unix cohttp-mirage cohttp-async cohttp-curl-async cohttp-curl-lwt cohttp-curl cohttp-top cohttp-bench
- run: opam install --with-test --deps-only http cohttp cohttp-lwt cohttp-lwt-unix cohttp-server-lwt-unix cohttp-async cohttp-curl-async cohttp-mirage cohttp-curl-lwt cohttp-curl cohttp-top cohttp-bench
- run: opam exec -- dune build http cohttp cohttp-lwt cohttp-lwt-unix cohttp-server-lwt-unix cohttp-async cohttp-curl-async cohttp-mirage cohttp-curl-lwt cohttp-curl cohttp-top cohttp-bench
- run: opam exec -- dune runtest http cohttp cohttp-lwt cohttp-lwt-unix cohttp-server-lwt-unix cohttp-async cohttp-curl-async cohttp-mirage cohttp-curl-lwt cohttp-curl cohttp-top cohttp-bench

build-test-cohttp-eio:
if: github.event.pull_request.draft == false
Expand Down Expand Up @@ -95,7 +139,5 @@ jobs:
alpha: https://github.com/kit-ty-kate/opam-alpha-repository.git
- run: opam install --with-test --deps-only cohttp-eio

- run: opam exec -- dune build cohttp-eio

- run: opam exec -- dune runtest cohttp-eio
8 changes: 3 additions & 5 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
## Unreleased

- cohttp-lwt server: call conn_closed before drainig the body of response on error (pirbo)
- cohttp-eio: Relax socket interface requirement on `Server.connection_handler` (mefyl #983)
- do not omit mandatory null Content-Length headers (mefyl #985)

## v6.0.0~alpha1 (2023-04-28)

- cohttp-async, cohttp-curl-async: compatibility with core/async v0.16.0 (mseri, dkalinichenko-js #976)
- cohttp-lwt server: call conn_closed before drainig the body of response on error (pirbo #982)
- cohttp-eio: Relax socket interface requirement on `Server.connection_handler`. (mefyl #983)
- cohttp,cohttp-async server: correctly close broken streams (reported by Stéphane Glondu, fix by samhot and anuragsoni)
- cohttp-eio: remove unused code from tests to work with Eio 0.8 (talex5 #967)
- Upgrade dune to v3.0 (bikallem #947)
Expand Down
8 changes: 4 additions & 4 deletions cohttp-async.opam
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ depends: [
"ocaml" {>= "4.08"}
"http" {= version}
"cohttp" {= version}
"async_kernel" {>= "v0.14.0"}
"async_unix" {>= "v0.14.0"}
"async" {>= "v0.14.0"}
"base" {>= "v0.11.0" & < "v0.16.0"}
"async_kernel" {>= "v0.16.0"}
"async_unix" {>= "v0.16.0"}
"async" {>= "v0.16.0"}
"base" {>= "v0.16.0"}
"core" {with-test}
"core_unix" {>= "v0.14.0"}
"conduit-async" {>= "1.2.0"}
Expand Down
2 changes: 1 addition & 1 deletion cohttp-async/bin/cohttp_server_async.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ let serve ~info ~docroot ~index uri path =
| `No | `Unknown ->
(* Do a directory listing *)
Sys.ls_dir file_name
>>= Deferred.List.map ~f:(fun f ->
>>= Deferred.List.map ~how:`Parallel ~f:(fun f ->
let file_name = file_name / f in
try_with (fun () ->
Unix.stat file_name >>| fun stat ->
Expand Down
4 changes: 2 additions & 2 deletions cohttp-async/examples/hello_world.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ let handler ~body:_ _sock req =
| _ -> Server.respond_string ~status:`Not_found "Route not found"

let start_server port () =
Caml.Printf.eprintf "Listening for HTTP on port %d\n" port;
Caml.Printf.eprintf "Try 'curl http://localhost:%d/test?hello=xyz'\n%!" port;
Stdlib.Printf.eprintf "Listening for HTTP on port %d\n" port;
Stdlib.Printf.eprintf "Try 'curl http://localhost:%d/test?hello=xyz'\n%!" port;
Server.create ~on_handler_error:`Raise
(Async.Tcp.Where_to_listen.of_port port)
handler
Expand Down
6 changes: 3 additions & 3 deletions cohttp-async/examples/receive_post.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ module Server = Cohttp_async.Server
(* compile with: $ corebuild receive_post.native -pkg cohttp.async *)

let start_server port () =
Caml.Printf.eprintf "Listening for HTTP on port %d\n" port;
Caml.Printf.eprintf "Try 'curl -X POST -d 'foo bar' http://localhost:%d\n"
Stdlib.Printf.eprintf "Listening for HTTP on port %d\n" port;
Stdlib.Printf.eprintf "Try 'curl -X POST -d 'foo bar' http://localhost:%d\n"
port;
Cohttp_async.Server.create ~on_handler_error:`Raise
(Async.Tcp.Where_to_listen.of_port port) (fun ~body _ req ->
match req |> Http.Request.meth with
| `POST ->
Body.to_string body >>= fun body ->
Caml.Printf.eprintf "Body: %s" body;
Stdlib.Printf.eprintf "Body: %s" body;
Server.respond `OK
| _ -> Server.respond `Method_not_allowed)
>>= fun _ -> Deferred.never ()
Expand Down
2 changes: 1 addition & 1 deletion cohttp-async/src/body.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let write_body write_body (body : t) writer =
match body with
| `Empty -> return ()
| `String s -> write_body writer s
| `Strings sl -> Deferred.List.iter sl ~f:(write_body writer)
| `Strings sl -> Deferred.List.iter ~how:`Sequential sl ~f:(write_body writer)
| `Pipe p -> Pipe.iter p ~f:(write_body writer)

let pipe_of_body read_chunk ic =
Expand Down
2 changes: 1 addition & 1 deletion cohttp-async/src/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ let callv ?interrupt ?ssl_config uri reqs =
Connection.connect ?interrupt ?ssl_config uri >>| fun connection ->
let responses =
Pipe.map' ~max_queue_length:1 reqs ~f:(fun reqs ->
Deferred.Queue.map reqs ~f:(fun (req, body) ->
Deferred.Queue.map ~how:`Sequential reqs ~f:(fun (req, body) ->
Connection.request ~body connection req))
in
Pipe.closed responses
Expand Down
8 changes: 4 additions & 4 deletions cohttp-async/src/io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ open Async_kernel
module IO = struct
module Writer = Async_unix.Writer
module Reader = Async_unix.Reader
module Format = Caml.Format
module Format = Stdlib.Format

let log_src_name = "cohttp.async.io"
let src = Logs.Src.create log_src_name ~doc:"Cohttp Async IO module"
Expand All @@ -44,7 +44,7 @@ module IO = struct
k ()
in
msgf @@ fun ?header:_ ?tags:_ fmt ->
Format.kfprintf k fmtr Caml.("@[" ^^ fmt ^^ "@]@.")
Format.kfprintf k fmtr Stdlib.("@[" ^^ fmt ^^ "@]@.")
in
{ Logs.report }

Expand All @@ -58,11 +58,11 @@ module IO = struct
Logs.set_reporter (default_reporter ()))

let check_debug norm_fn debug_fn =
match Caml.Sys.getenv "COHTTP_DEBUG" with
match Stdlib.Sys.getenv "COHTTP_DEBUG" with
| _ ->
Lazy.force set_log;
debug_fn
| exception Caml.Not_found -> norm_fn
| exception Stdlib.Not_found -> norm_fn

type 'a t = 'a Deferred.t

Expand Down
4 changes: 2 additions & 2 deletions cohttp-async/test/test_async_integration.ml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ let ts =
reqs |> Pipe.of_list |> Client.callv uri >>= fun responses ->
responses |> Pipe.to_list >>= fun resps ->
resps
|> Deferred.List.iter ~f:(fun (_resp, body) ->
|> Deferred.List.iter ~how:`Sequential ~f:(fun (_resp, body) ->
let expected_body = body_q |> Queue.dequeue_exn in
body |> Body.to_string >>| fun body ->
assert_equal ~printer expected_body body)
Expand Down Expand Up @@ -113,7 +113,7 @@ let ts =
("Pipe with empty strings", Pipe.of_list [ ""; ""; "" ], true);
]
in
Deferred.List.iter tests ~f:(fun (msg, pipe, expected) ->
Deferred.List.iter ~how:`Sequential tests ~f:(fun (msg, pipe, expected) ->
is_empty (`Pipe pipe) >>| fun real ->
assert_equal ~msg expected real)
>>= fun () ->
Expand Down
2 changes: 1 addition & 1 deletion cohttp-bench/async_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let start_server port () =
handler
>>= fun server ->
Deferred.forever () (fun () ->
after Time.Span.(of_sec 0.5) >>| fun () ->
after Time_float.Span.(of_sec 0.5) >>| fun () ->
Log.Global.printf "Active connections: %d" (Server.num_connections server));
Deferred.never ()

Expand Down
2 changes: 1 addition & 1 deletion cohttp-curl-async.opam
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ depends: [
"http" {= version}
"stringext"
"cohttp-curl" {= version}
"core"
"core" {>= "v0.16.0"}
"core_unix" {>= "v0.14.0"}
"async_kernel"
"async_unix"
Expand Down
2 changes: 1 addition & 1 deletion cohttp-curl-async/bin/curl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Curl = Cohttp_curl_async
module Sexp = Sexplib0.Sexp
open Async_kernel
module Writer = Async_unix.Writer
module Time = Core.Time
module Time = Core.Time_float

let ( let* ) x f = Deferred.bind x ~f

Expand Down
4 changes: 2 additions & 2 deletions cohttp-curl-async/src/cohttp_curl_async.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
open Async_kernel
module Time = Core.Time
module Time = Core.Time_float
module Fd = Async_unix.Fd
module Clock = Async_unix.Clock

Expand Down Expand Up @@ -164,7 +164,7 @@ module Request = struct
let base =
let timeout_ms =
Option.map
(fun timeout -> Core.Time.Span.to_ms timeout |> int_of_float)
(fun timeout -> Time.Span.to_ms timeout |> int_of_float)
timeout
in
Cohttp_curl.Request.create ?timeout_ms ?headers method_ ~uri ~input
Expand Down
2 changes: 1 addition & 1 deletion cohttp-curl-async/src/cohttp_curl_async.mli
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module Request : sig
handled. *)

val create :
?timeout:Core.Time.Span.t (** timeout for the request *) ->
?timeout:Core.Time_float.Span.t (** timeout for the request *) ->
?headers:Http.Header.t (** http headers *) ->
Http.Method.t (** http method *) ->
uri:string (** uri *) ->
Expand Down
63 changes: 34 additions & 29 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,30 @@
(package
(name cohttp-lwt-unix)
(synopsis "CoHTTP implementation for Unix and Windows using Lwt")
(description "\
An implementation of an HTTP client and server using the Lwt
concurrency library. See the `Cohttp_lwt_unix` module for information
on how to use this. The package also installs `cohttp-curl-lwt`
and a `cohttp-server-lwt` binaries for quick uses of a HTTP(S)
client and server respectively.

Although the name implies that this only works under Unix, it
should also be fine under Windows too.
")
(description
"An implementation of an HTTP client and server using the Lwt\nconcurrency library. See the `Cohttp_lwt_unix` module for information\non how to use this. The package also installs `cohttp-curl-lwt`\nand a `cohttp-server-lwt` binaries for quick uses of a HTTP(S)\nclient and server respectively.\n\nAlthough the name implies that this only works under Unix, it\nshould also be fine under Windows too.\n")
(depends
(ocaml (>= 4.08))
(http (= :version))
(cohttp (= :version))
(cohttp-lwt (= :version))
(cmdliner (>= 1.1.0))
(lwt (>= 3.0.0))
(conduit-lwt (>= 5.0.0))
(conduit-lwt-unix (>= 5.0.0))
(fmt (>= 0.8.2))
(ocaml
(>= 4.08))
(http
(= :version))
(cohttp
(= :version))
(cohttp-lwt
(= :version))
(cmdliner
(>= 1.1.0))
(lwt
(>= 3.0.0))
(conduit-lwt
(>= 5.0.0))
(conduit-lwt-unix
(>= 5.0.0))
(fmt
(>= 0.8.2))
base-unix
(ppx_sexp_conv (>= v0.13.0))
(ppx_sexp_conv
(>= v0.13.0))
magic-mime
logs
(ounit :with-test)))
Expand Down Expand Up @@ -174,15 +176,13 @@ should also be fine under Windows too.
(cohttp
(= :version))
(async_kernel
(>= v0.14.0))
(>= v0.16.0))
(async_unix
(>= v0.14.0))
(>= v0.16.0))
(async
(>= v0.14.0))
(>= v0.16.0))
(base
(and
(>= v0.11.0)
(< v0.16.0)))
(>= v0.16.0))
(core :with-test)
(core_unix
(>= v0.14.0))
Expand Down Expand Up @@ -255,7 +255,10 @@ should also be fine under Windows too.
:with-test
(>= v0.13.0)))
(core_bench :with-test)
(crowbar (and :with-test (>= 0.2)))
(crowbar
(and
:with-test
(>= 0.2)))
(sexplib0 :with-test)))

(package
Expand Down Expand Up @@ -319,8 +322,10 @@ should also be fine under Windows too.
stringext
(cohttp-curl
(= :version))
core
(core_unix (>= v0.14.0))
(core
(>= v0.16.0))
(core_unix
(>= v0.14.0))
async_kernel
async_unix
(cohttp-async
Expand Down

0 comments on commit d5f776c

Please sign in to comment.