Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions cohttp.opam
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ depends: [
"sexplib0"
"ppx_fields_conv" {>= "v0.9.0"}
"ppx_sexp_conv" {>= "v0.13.0"}
"ppx_compare" {>= "v0.13.0"}
"stdlib-shims"
"stringext"
"base64" {>= "3.1.0"}
"stdlib-shims"
Expand Down
10 changes: 6 additions & 4 deletions cohttp/scripts/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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 =
Expand Down Expand Up @@ -296,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) =
Expand Down Expand Up @@ -360,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;
Expand Down
6 changes: 3 additions & 3 deletions cohttp/src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
(public_name cohttp)
(synopsis "Co-operative Client/Server HTTP library.")
(preprocess
(pps ppx_fields_conv ppx_sexp_conv))
(libraries re stringext uri uri-sexp fieldslib sexplib0 bytes base64
stdlib-shims))
(pps ppx_compare ppx_fields_conv ppx_sexp_conv))
(libraries ppx_compare.runtime-lib re stringext uri uri-sexp fieldslib
sexplib0 bytes base64 stdlib-shims))

(ocamllex accept_lexer)

Expand Down
3 changes: 2 additions & 1 deletion cohttp/src/request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*
}}}*)

open Ppx_compare_lib.Builtin
open Sexplib0.Sexp_conv

type t = {
Expand All @@ -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

Expand Down
4 changes: 3 additions & 1 deletion cohttp/src/response.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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=Header.init ()) () =
let encoding =
Expand Down
4 changes: 2 additions & 2 deletions cohttp/src/s.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -112,7 +112,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]

(* The response creates by [make ~encoding ~headers ()] has an
encoding value determined from the content of [headers] or if no
Expand Down
5 changes: 4 additions & 1 deletion cohttp/src/transfer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cohttp/src/transfer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down