New upstream version 5.2.0
authorStephane Glondu <steph@glondu.net>
Sun, 8 Oct 2023 18:42:15 +0000 (20:42 +0200)
committerStephane Glondu <steph@glondu.net>
Sun, 8 Oct 2023 18:42:15 +0000 (20:42 +0200)
19 files changed:
CHANGES.md
cohttp-async.opam
cohttp-lwt-jsoo.opam
cohttp-lwt-unix.opam
cohttp-lwt-unix/bin/cohttp_curl_lwt.ml
cohttp-lwt-unix/bin/cohttp_proxy_lwt.ml
cohttp-lwt-unix/bin/cohttp_server_lwt.ml
cohttp-lwt-unix/bin/dune
cohttp-lwt.opam
cohttp-lwt/src/server.ml
cohttp-mirage.opam
cohttp-mirage/src/client.ml
cohttp-mirage/src/io.ml
cohttp-mirage/src/io.mli
cohttp-mirage/src/static.ml
cohttp-mirage/src/static.mli
cohttp-top.opam
cohttp.opam
dune-project

index 0a4aa0f99b4663b4ecca55e61a37fa4c13ff8855..0e604c54fd93b01322dd9559c8f5d2d46ce089a5 100644 (file)
@@ -1,3 +1,7 @@
+## v5.2.0 (2023-07-07)
+
+- cohttp-lwt server: call conn_closed before drainig the body of response on error (pirbo)
+
 ## v5.1.0 (2023-04-04)
 
 - cohttp,cohttp-async server: correctly close broken streams (reported by Stéphane Glondu, fix by samhot and anuragsoni)
   + ```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)
index 594f6366f211a477c1e9479d4cf475f6e6c0d6ca..18fc6eacc99ba792978fe561fed1a4f260517fee 100644 (file)
@@ -1,3 +1,4 @@
+version: "5.2.0"
 opam-version: "2.0"
 maintainer: "anil@recoil.org"
 authors: [
@@ -27,9 +28,9 @@ depends: [
   "dune" {>= "2.0"}
   "async_kernel" {>= "v0.14.0"}
   "async_unix" {>= "v0.14.0"}
-  "async" {>= "v0.14.0"}
+  "async" {>= "v0.14.0" & < "v0.16.0"}
   "base" {>= "v0.11.0"}
-  "core" {with-test}
+  "core" {with-test & < "v0.15.0"}
   "core_unix" {>= "v0.14.0"}
   "cohttp" {= version}
   "conduit-async" {>= "1.2.0"}
@@ -50,4 +51,4 @@ build: [
   ["dune" "runtest" "-p" name "-j" jobs] {with-test}
 ]
 available: arch != "s390x"
-dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
+dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
\ No newline at end of file
index 24c7fbd200548e39b79d094f199b3c2757e66e45..dfb8f06f11ed56484ec62537f465a4c4f54f9304 100644 (file)
@@ -1,3 +1,4 @@
+version: "5.2.0"
 opam-version: "2.0"
 maintainer: "anil@recoil.org"
 authors: [
@@ -39,4 +40,4 @@ build: [
   ["dune" "build" "-p" name "-j" jobs]
   ["dune" "runtest" "-p" name "-j" jobs] {with-test}
 ]
-dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
+dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
\ No newline at end of file
index 9bf319cabadc955bb5748182090c315000cc7f1c..fbcd809f1ae9e74a5484b11d7e9005834320080f 100644 (file)
@@ -1,3 +1,4 @@
+version: "5.2.0"
 opam-version: "2.0"
 maintainer: "anil@recoil.org"
 authors: [
@@ -29,7 +30,7 @@ depends: [
   "dune" {>= "2.0"}
   "conduit-lwt" {>= "5.0.0"}
   "conduit-lwt-unix" {>= "5.0.0"}
-  "cmdliner"
+  "cmdliner" {>= "1.1.0"}
   "magic-mime"
   "logs"
   "fmt" {>= "0.8.2"}
@@ -44,4 +45,4 @@ build: [
   ["dune" "build" "-p" name "-j" jobs]
   ["dune" "runtest" "-p" name "-j" jobs] {with-test}
 ]
-dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
+dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
\ No newline at end of file
index c31dafebdd6a8023696c2fb54d5ee444dbc401d2..4adc748a4d6cb0b1ee9bf17bcd1cd97c6713ffe8 100644 (file)
@@ -58,7 +58,7 @@ let run_client level ofile uri meth =
 open Cmdliner
 
 let uri =
-  let loc : Uri.t Arg.converter =
+  let loc : Uri.t Arg.conv =
     let parse s =
       try `Ok (Uri.of_string s) with Failure _ -> `Error "unable to parse URI"
     in
@@ -81,25 +81,29 @@ let ofile =
   Arg.(value & opt (some string) None & info [ "o" ] ~docv:"FILE" ~doc)
 
 let cmd =
-  let doc = "retrieve a remote URI contents" in
-  let man =
-    [
-      `S "DESCRIPTION";
-      `P
-        "$(tname) fetches the remote $(i,URI) and prints it to standard \
-         output. The output file can also be specified with the $(b,-o) \
-         option, and more verbose debugging out obtained via the $(b,-v) \
-         option.";
-      `S "BUGS";
-      `P
-        "Report them via e-mail to <mirageos-devel@lists.xenproject.org>, or \
-         on the issue tracker at \
-         <https://github.com/mirage/ocaml-cohttp/issues>";
-      `S "SEE ALSO";
-      `P "$(b,curl)(1), $(b,wget)(1)";
-    ]
+  let info =
+    let version = Cohttp.Conf.version in
+    let doc = "retrieve a remote URI contents" in
+    let man =
+      [
+        `S "DESCRIPTION";
+        `P
+          "$(tname) fetches the remote $(i,URI) and prints it to standard \
+           output. The output file can also be specified with the $(b,-o) \
+           option, and more verbose debugging out obtained via the $(b,-v) \
+           option.";
+        `S "BUGS";
+        `P
+          "Report them via e-mail to <mirageos-devel@lists.xenproject.org>, or \
+           on the issue tracker at \
+           <https://github.com/mirage/ocaml-cohttp/issues>";
+        `S "SEE ALSO";
+        `P "$(b,curl)(1), $(b,wget)(1)";
+      ]
+    in
+    Cmd.info "cohttp-curl" ~version ~doc ~man
   in
-  ( Term.(pure run_client $ verb $ ofile $ uri $ meth),
-    Term.info "cohttp-curl" ~version:Cohttp.Conf.version ~doc ~man )
+  let term = Term.(const run_client $ verb $ ofile $ uri $ meth) in
+  Cmd.v info term
 
-let () = match Term.eval cmd with `Error _ -> exit 1 | _ -> exit 0
+let () = exit @@ Cmd.eval cmd
index 9fddad8639aaf92380554610a09e729a66d7be37..1f698016310edf80470a7b1ffbde61f3fb0859fc 100644 (file)
@@ -101,19 +101,25 @@ let ssl_key =
   Arg.(value & opt (some string) None & info [ "k" ] ~docv:"SSL_KEY" ~doc)
 
 let cmd =
-  let doc = "a simple http proxy" in
-  let man =
-    [
-      `S "DESCRIPTION";
-      `P "$(tname) sets up a simple http proxy with lwt as backend";
-      `S "BUGS";
-      `P
-        "Report them via e-mail to <mirageos-devel@lists.xenproject.org>, or \
-         on the issue tracker at \
-         <https://github.com/mirage/ocaml-cohttp/issues>";
-    ]
+  let info =
+    let version = Cohttp.Conf.version in
+    let doc = "a simple http proxy" in
+    let man =
+      [
+        `S "DESCRIPTION";
+        `P "$(tname) sets up a simple http proxy with lwt as backend";
+        `S "BUGS";
+        `P
+          "Report them via e-mail to <mirageos-devel@lists.xenproject.org>, or \
+           on the issue tracker at \
+           <https://github.com/mirage/ocaml-cohttp/issues>";
+      ]
+    in
+    Cmd.info "cohttp-proxy" ~version ~doc ~man
   in
-  ( Term.(pure lwt_start_proxy $ port $ host $ verb $ ssl_cert $ ssl_key),
-    Term.info "cohttp-proxy" ~version:Cohttp.Conf.version ~doc ~man )
+  let term =
+    Term.(const lwt_start_proxy $ port $ host $ verb $ ssl_cert $ ssl_key)
+  in
+  Cmd.v info term
 
-let () = match Term.eval cmd with `Error _ -> exit 1 | _ -> exit 0
+let () = exit @@ Cmd.eval cmd
index b4c2b63b8ae45676f366b2651091e166472ac63f..57b0f6d268a4d7f16bc70e19bea506fb7ce01204 100644 (file)
@@ -163,19 +163,25 @@ let doc_root =
   Arg.(value & pos 0 dir "." & info [] ~docv:"DOCROOT" ~doc)
 
 let cmd =
-  let doc = "a simple http server" in
-  let man =
-    [
-      `S "DESCRIPTION";
-      `P "$(tname) sets up a simple http server with lwt as backend";
-      `S "BUGS";
-      `P
-        "Report them via e-mail to <mirageos-devel@lists.xenproject.org>, or \
-         on the issue tracker at \
-         <https://github.com/mirage/ocaml-cohttp/issues>";
-    ]
+  let info =
+    let version = Cohttp.Conf.version in
+    let doc = "a simple http server" in
+    let man =
+      [
+        `S "DESCRIPTION";
+        `P "$(tname) sets up a simple http server with lwt as backend";
+        `S "BUGS";
+        `P
+          "Report them via e-mail to <mirageos-devel@lists.xenproject.org>, or \
+           on the issue tracker at \
+           <https://github.com/mirage/ocaml-cohttp/issues>";
+      ]
+    in
+    Cmd.info "cohttp-server" ~version ~doc ~man
+  in
+  let term =
+    Term.(const lwt_start_server $ doc_root $ port $ host $ index $ verb $ tls)
   in
-  ( Term.(pure lwt_start_server $ doc_root $ port $ host $ index $ verb $ tls),
-    Term.info "cohttp-server" ~version:Cohttp.Conf.version ~doc ~man )
+  Cmd.v info term
 
-let () = match Term.eval cmd with `Error _ -> exit 1 | _ -> exit 0
+let () = exit @@ Cmd.eval cmd
index 63e95e9032098be3f87c3b40a217d66944f169ca..b8ae61a03e7992cd34c23c63dc52abde1e56b1ce 100644 (file)
@@ -1,6 +1,14 @@
 (executables
  (names cohttp_curl_lwt cohttp_proxy_lwt cohttp_server_lwt)
- (libraries cohttp-lwt-unix cohttp_server logs logs.lwt logs.fmt logs.cli
-   cmdliner conduit-lwt fmt.tty)
+ (libraries
+  cohttp-lwt-unix
+  cohttp_server
+  logs
+  logs.lwt
+  logs.fmt
+  logs.cli
+  cmdliner
+  conduit-lwt
+  fmt.tty)
  (package cohttp-lwt-unix)
  (public_names cohttp-curl-lwt cohttp-proxy-lwt cohttp-server-lwt))
index bd1bd54dab89221e0c384aa86ef8034df584883b..a88bfcc78b399e8db4b8c38319c298f5f9b403da 100644 (file)
@@ -1,3 +1,4 @@
+version: "5.2.0"
 opam-version: "2.0"
 maintainer: "anil@recoil.org"
 authors: [
@@ -39,4 +40,4 @@ build: [
   ["dune" "build" "-p" name "-j" jobs]
   ["dune" "runtest" "-p" name "-j" jobs] {with-test}
 ]
-dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
+dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
\ No newline at end of file
index 6ec5b2038a704ff4b39b984b5b30b5edcfb9c576..922ee8851f2d03a017897a640e373e50da0378de 100644 (file)
@@ -111,52 +111,58 @@ module Make (IO : S.IO) = struct
                 `Response rsp))
       (fun () -> Body.drain_body body)
 
-  let handle_response ~keep_alive oc res body handle_client =
+  let handle_response ~keep_alive oc res body conn_closed handle_client =
     IO.catch (fun () ->
         let flush = Response.flush res in
         Response.write ~flush
           (fun writer -> Body.write_body (Response.write_body writer) body)
-          res oc
-        >>= fun () -> if keep_alive then handle_client oc else Lwt.return_unit)
+          res oc)
     >>= function
-    | Ok () -> Lwt.return_unit
+    | Ok () ->
+        if keep_alive then handle_client oc
+        else
+          let () = conn_closed () in
+          Lwt.return_unit
     | Error e ->
         Log.info (fun m -> m "IO error while writing body: %a" IO.pp_error e);
+        conn_closed ();
         Body.drain_body body
 
-
-  let rec handle_client ic oc conn callback =
+  let rec handle_client ic oc conn spec =
     Request.read ic >>= function
-    | `Eof -> Lwt.return_unit
+    | `Eof ->
+        spec.conn_closed conn;
+        Lwt.return_unit
     | `Invalid data ->
         Log.err (fun m -> m "invalid input %s while handling client" data);
+        spec.conn_closed conn;
         Lwt.return_unit
     | `Ok req -> (
         let body = read_body ic req in
-        handle_request callback conn req body >>= function
+        handle_request spec.callback conn req body >>= function
         | `Response (res, body) ->
             let keep_alive = Request.is_keep_alive req in
-            handle_response ~keep_alive oc res body (fun oc ->
-              handle_client ic oc conn callback)
+            handle_response ~keep_alive oc res body
+              (fun () -> spec.conn_closed conn)
+              (fun oc -> handle_client ic oc conn spec)
         | `Expert (res, io_handler) ->
             Response.write_header res oc >>= fun () ->
-            io_handler ic oc >>= fun () -> 
-            handle_client ic oc conn callback)
+            io_handler ic oc >>= fun () -> handle_client ic oc conn spec)
 
   let callback spec io_id ic oc =
     let conn_id = Cohttp.Connection.create () in
     let conn_closed () = spec.conn_closed (io_id, conn_id) in
-    Lwt.finalize
+    Lwt.catch
       (fun () ->
-        IO.catch (fun () -> handle_client ic oc (io_id, conn_id) spec.callback)
+        IO.catch (fun () -> handle_client ic oc (io_id, conn_id) spec)
         >>= function
         | Ok () -> Lwt.return_unit
         | Error e ->
             Log.info (fun m ->
                 m "IO error while handling client: %a" IO.pp_error e);
+            conn_closed ();
             Lwt.return_unit)
-      (fun () ->
-        (* Clean up resources when the response stream terminates and call
-         * the user callback *)
-        conn_closed () |> Lwt.return)
+      (fun e ->
+        conn_closed ();
+        Lwt.fail e)
 end
index 2e713279c4c6757475c62325ecb9a8cb8bbb9447..d767aa50309a6bbb65c546ff0d1359d01773720a 100644 (file)
@@ -1,3 +1,4 @@
+version: "5.2.0"
 opam-version: "2.0"
 maintainer: "anil@recoil.org"
 authors: ["Anil Madhavapeddy" "Thomas Gazagnaire"]
@@ -38,4 +39,4 @@ build: [
   ["dune" "build" "-p" name "-j" jobs]
   ["dune" "runtest" "-p" name "-j" jobs] {with-test}
 ]
-dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
+dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
\ No newline at end of file
index bd65b06b13426f3f0433bac883d6eddb1562af8b..b34ebfdf3d9850302a9d7574ad48d3f6b27269a6 100644 (file)
@@ -14,7 +14,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
- * %%NAME%% %%VERSION%%
+ * cohttp v5.2.0
  *)
 
 open Lwt.Infix
index fe2f9d7668f5d25a93cd132efe3b8b0b03f5ebb1..84b54661ec094d9a99ac5294a53040794e7fdbaa 100644 (file)
@@ -14,7 +14,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
- * %%NAME%% %%VERSION%%
+ * cohttp v5.2.0
  *)
 
 open Lwt.Infix
index 23e9792f90fdc0107d8eb79a5acec2599fac6b02..10c87103a68e2f03bc9d28a2f130223eba91ccfc 100644 (file)
@@ -14,7 +14,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
- * %%NAME%% %%VERSION%%
+ * cohttp v5.2.0
  *)
 
 (** Cohttp IO implementation using Mirage channels. *)
index 6ca5b56fd7db593ab704e6eb5ab3324781382ad6..bba69cf66234266cbdd185bad8544366f411941c 100644 (file)
@@ -14,7 +14,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
- * %%NAME%% %%VERSION%%
+ * cohttp v5.2.0
  *)
 
 module Key = Mirage_kv.Key
index 8f73c992c373bbfaab2e270f4b89fd3c25b3c55c..9ee4763a163762a346a824aeaa75ae11aa91a696 100644 (file)
@@ -14,7 +14,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  *
- * %%NAME%% %%VERSION%%
+ * cohttp v5.2.0
  *)
 
 (** Serve static HTTP sites from a Mirage key-value store. *)
index 9b21332b863b388e8f8a1cf90f50deb537e2bd3f..d4b5b2ee0bdfbb08c03871f86038876c7c485c50 100644 (file)
@@ -1,3 +1,4 @@
+version: "5.2.0"
 opam-version: "2.0"
 maintainer: "anil@recoil.org"
 authors: [
@@ -30,4 +31,4 @@ build: [
   ["dune" "build" "-p" name "-j" jobs]
   ["dune" "runtest" "-p" name "-j" jobs] {with-test}
 ]
-dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
+dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
\ No newline at end of file
index 9e6a95ac607dc1ccd4289567f002410d179da046..7e73c55b9f257b96d5d8886132fdd07ebd4999c4 100644 (file)
@@ -1,3 +1,4 @@
+version: "5.2.0"
 opam-version: "2.0"
 maintainer: "anil@recoil.org"
 authors: [
@@ -51,4 +52,4 @@ build: [
   ["dune" "build" "-p" name "-j" jobs]
   ["dune" "runtest" "-p" name "-j" jobs] {with-test}
 ]
-dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
+dev-repo: "git+https://github.com/mirage/ocaml-cohttp.git"
\ No newline at end of file
index ad62607fd3a32b5183920b06713657a13799b12e..c3014fe03457004979a885748f32fef887877a4c 100644 (file)
@@ -1,2 +1,3 @@
 (lang dune 2.0)
 (name cohttp)
+(version v5.2.0)