From bf857e7f5d7a2524eef0607cd586ba543f4f891b Mon Sep 17 00:00:00 2001 From: Matthew Saffer Date: Mon, 6 Jan 2020 11:04:03 -0500 Subject: [PATCH 1/4] Add ppx_compare to provide comparison functions for Response.t --- cohttp.opam | 1 + cohttp/scripts/generate.ml | 7 ++++--- cohttp/src/dune | 2 +- cohttp/src/response.ml | 4 +++- cohttp/src/s.ml | 2 +- cohttp/src/transfer.ml | 5 ++++- cohttp/src/transfer.mli | 2 +- 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/cohttp.opam b/cohttp.opam index a4df15e1cb..ca68a4f7b0 100644 --- a/cohttp.opam +++ b/cohttp.opam @@ -41,6 +41,7 @@ depends: [ "sexplib0" "ppx_fields_conv" {>= "v0.9.0"} "ppx_sexp_conv" {>= "v0.13.0"} + "ppx_compare" {>= "v0.13.0"} "stringext" "base64" {>= "3.1.0"} "stdlib-shims" diff --git a/cohttp/scripts/generate.ml b/cohttp/scripts/generate.ml index 935f6df529..ced20a6804 100644 --- a/cohttp/scripts/generate.ml +++ b/cohttp/scripts/generate.ml @@ -193,7 +193,7 @@ let output_type oc ~mli t = else append oc " | %s%s" c.constr doc ) t.codes; - append oc " ] [@@deriving sexp]"; + append oc " ] [@@deriving compare, sexp]"; if mli then append oc "(** %s *)" (String.capitalize_ascii t.section); append oc "" @@ -202,9 +202,10 @@ let output_status_types oc ~mli t = List.iter (output_type oc ~mli) t; append oc "type status = ["; List.iter (fun t -> append oc " | %s_status" t.section) t; - append oc "] [@@deriving sexp]"; + append oc "] [@@deriving compare, sexp]"; append oc ""; - append oc "type status_code = [`Code of int | status ] [@@deriving sexp]"; + if not mli then append oc "let compare_int = Int.compare\n" else (); + append oc "type status_code = [`Code of int | status ] [@@deriving compare, sexp]"; append oc "" let iter fn s = diff --git a/cohttp/src/dune b/cohttp/src/dune index a3a15d0701..c73172c622 100644 --- a/cohttp/src/dune +++ b/cohttp/src/dune @@ -9,7 +9,7 @@ (name cohttp) (public_name cohttp) (synopsis "Co-operative Client/Server HTTP library.") - (preprocess (pps ppx_fields_conv ppx_sexp_conv)) + (preprocess (pps ppx_compare ppx_fields_conv ppx_sexp_conv)) (libraries re stringext uri uri-sexp fieldslib sexplib0 bytes base64 stdlib-shims)) (ocamllex accept_lexer) diff --git a/cohttp/src/response.ml b/cohttp/src/response.ml index 8bcedefde6..2429db8e85 100644 --- a/cohttp/src/response.ml +++ b/cohttp/src/response.ml @@ -16,13 +16,15 @@ open Sexplib0.Sexp_conv +let compare_bool = Bool.compare + type t = { encoding: Transfer.encoding; headers: Header.t; version: Code.version; status: Code.status_code; flush: bool; -} [@@deriving fields, sexp] +} [@@deriving compare, fields, sexp] let make ?(version=`HTTP_1_1) ?(status=`OK) ?(flush=false) ?(encoding=Transfer.Chunked) ?headers () = let headers = match headers with None -> Header.init () |Some h -> h in diff --git a/cohttp/src/s.ml b/cohttp/src/s.ml index b515b86322..27d0882d96 100644 --- a/cohttp/src/s.ml +++ b/cohttp/src/s.ml @@ -111,7 +111,7 @@ module type Response = sig version: Code.version; (** (** HTTP version, usually 1.1 *) *) status: Code.status_code; (** HTTP status code of the response *) flush: bool; - } [@@deriving fields, sexp] + } [@@deriving compare, fields, sexp] val make : ?version:Code.version -> diff --git a/cohttp/src/transfer.ml b/cohttp/src/transfer.ml index f92e6402bb..894bc91065 100644 --- a/cohttp/src/transfer.ml +++ b/cohttp/src/transfer.ml @@ -16,10 +16,13 @@ open Sexplib0.Sexp_conv +let compare_int64 = Int64.compare + type encoding = | Chunked | Fixed of int64 - | Unknown [@@deriving sexp] + | Unknown +[@@deriving compare, sexp] type chunk = | Chunk of string diff --git a/cohttp/src/transfer.mli b/cohttp/src/transfer.mli index a3701e09d0..65d2a64afd 100644 --- a/cohttp/src/transfer.mli +++ b/cohttp/src/transfer.mli @@ -24,7 +24,7 @@ type encoding = | Chunked (** dynamic chunked encoding *) | Fixed of int64 (** fixed size content *) | Unknown (** unknown body size, which leads to best-effort *) -[@@deriving sexp] +[@@deriving compare, sexp] (** A chunk of body that also signals if there to more to arrive *) type chunk = From c399b6689412a825875ebc1489a9c82cea0c040b Mon Sep 17 00:00:00 2001 From: Matthew Saffer Date: Thu, 9 Jan 2020 14:26:15 -0500 Subject: [PATCH 2/4] Use stdlib-shims per mseri --- cohttp.opam | 1 + 1 file changed, 1 insertion(+) diff --git a/cohttp.opam b/cohttp.opam index ca68a4f7b0..9557fbdbbc 100644 --- a/cohttp.opam +++ b/cohttp.opam @@ -42,6 +42,7 @@ depends: [ "ppx_fields_conv" {>= "v0.9.0"} "ppx_sexp_conv" {>= "v0.13.0"} "ppx_compare" {>= "v0.13.0"} + "stdlib-shims" {>= "v0.1.0"} "stringext" "base64" {>= "3.1.0"} "stdlib-shims" From 0048c92004f989e8a066f165e6c43e8f016a6484 Mon Sep 17 00:00:00 2001 From: Matthew Saffer Date: Thu, 9 Jan 2020 15:24:46 -0500 Subject: [PATCH 3/4] Remove version requirement for stdlib-shims --- cohttp.opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cohttp.opam b/cohttp.opam index 9557fbdbbc..2591148174 100644 --- a/cohttp.opam +++ b/cohttp.opam @@ -42,7 +42,7 @@ depends: [ "ppx_fields_conv" {>= "v0.9.0"} "ppx_sexp_conv" {>= "v0.13.0"} "ppx_compare" {>= "v0.13.0"} - "stdlib-shims" {>= "v0.1.0"} + "stdlib-shims" "stringext" "base64" {>= "3.1.0"} "stdlib-shims" From 8bd88ac61902ae1abf1f6d5e785cabb1de581d70 Mon Sep 17 00:00:00 2001 From: Calascibetta Romain Date: Mon, 2 Nov 2020 12:04:27 +0100 Subject: [PATCH 4/4] Add ppx_compare on Request.t --- cohttp/scripts/generate.ml | 3 ++- cohttp/src/dune | 4 ++-- cohttp/src/request.ml | 3 ++- cohttp/src/s.ml | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/cohttp/scripts/generate.ml b/cohttp/scripts/generate.ml index ced20a6804..affb0f7c2c 100644 --- a/cohttp/scripts/generate.ml +++ b/cohttp/scripts/generate.ml @@ -297,7 +297,7 @@ let output_gen_types oc (_name, typ, gens) = append oc "type %s = [" typ; List.iter (fun { constr; _ } -> append oc " | %s" constr) gens; append oc " | `Other of string"; - append oc "] [@@deriving sexp]"; + append oc "] [@@deriving compare, sexp]"; append oc "" let output_gen_convert oc ~mli (name, typ, gens) = @@ -361,6 +361,7 @@ let meth = ("method", "meth", known_methods) let gen oc ~mli = append oc "(* Auto-Generated by 'ocaml generate.ml' *)"; append oc "open! Sexplib0.Sexp_conv"; + if not mli then append oc "open Ppx_compare_lib.Builtin"; append oc ""; output_gen_types oc version; output_gen_types oc meth; diff --git a/cohttp/src/dune b/cohttp/src/dune index e20b305cd5..e0d8f93747 100644 --- a/cohttp/src/dune +++ b/cohttp/src/dune @@ -19,8 +19,8 @@ (synopsis "Co-operative Client/Server HTTP library.") (preprocess (pps ppx_compare ppx_fields_conv ppx_sexp_conv)) - (libraries re stringext uri uri-sexp fieldslib sexplib0 bytes base64 - stdlib-shims)) + (libraries ppx_compare.runtime-lib re stringext uri uri-sexp fieldslib + sexplib0 bytes base64 stdlib-shims)) (ocamllex accept_lexer) diff --git a/cohttp/src/request.ml b/cohttp/src/request.ml index c07f2f49af..cca81a5b1f 100644 --- a/cohttp/src/request.ml +++ b/cohttp/src/request.ml @@ -14,6 +14,7 @@ * }}}*) +open Ppx_compare_lib.Builtin open Sexplib0.Sexp_conv type t = { @@ -23,7 +24,7 @@ type t = { resource: string; version: Code.version; encoding: Transfer.encoding; -} [@@deriving fields, sexp] +} [@@deriving compare, fields, sexp] let fixed_zero = Transfer.Fixed Int64.zero diff --git a/cohttp/src/s.ml b/cohttp/src/s.ml index 991254c6ec..e34cea848c 100644 --- a/cohttp/src/s.ml +++ b/cohttp/src/s.ml @@ -88,7 +88,7 @@ module type Request = sig resource: string; (** Request path and query *) version: Code.version; (** HTTP version, usually 1.1 *) encoding: Transfer.encoding; (** transfer encoding of this HTTP request *) - } [@@deriving fields, sexp] + } [@@deriving compare, fields, sexp] val make : ?meth:Code.meth -> ?version:Code.version -> ?encoding:Transfer.encoding -> ?headers:Header.t ->