diff --git a/CHANGES.md b/CHANGES.md index 5643cc6e98..7a36b75d33 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,6 @@ ## current +- Remove dependency to base (@samoht #745) - fix opam files and dependencies - add GitHub Actions workflow (@smorimoto #739) - lwt_jsoo: Forward exceptions to caller when response is null (@mefyl #738) diff --git a/cohttp-lwt-unix/test/test_parser.ml b/cohttp-lwt-unix/test/test_parser.ml index 9d26fec911..000d1ea56b 100644 --- a/cohttp-lwt-unix/test/test_parser.ml +++ b/cohttp-lwt-unix/test/test_parser.ml @@ -276,7 +276,7 @@ let mutate_simple_req () = ~headers:(Header.init_with "foo" "bar") (Uri.of_string "/foo/bar") in - let req = Fieldslib.Field.fset Request.Fields.meth req `POST in + let req = { req with Request.meth = `POST } in write_req expected req let make_simple_res () = diff --git a/cohttp.opam b/cohttp.opam index 6cca69a75a..4a9995d4e1 100644 --- a/cohttp.opam +++ b/cohttp.opam @@ -33,15 +33,12 @@ doc: "https://mirage.github.io/ocaml-cohttp/" bug-reports: "https://github.com/mirage/ocaml-cohttp/issues" depends: [ "ocaml" {>= "4.08"} - "dune" {>= "1.1.0"} + "dune" {>= "2.0.0"} "re" {>= "1.9.0"} "uri" {>= "2.0.0"} "uri-sexp" - "fieldslib" "sexplib0" - "ppx_fields_conv" {>= "v0.9.0"} "ppx_sexp_conv" {>= "v0.13.0"} - "ppx_compare" {>= "v0.13.0"} "stringext" "base64" {>= "3.1.0"} "fmt" {with-test} diff --git a/cohttp/scripts/generate.ml b/cohttp/scripts/generate.ml index b93d7059cc..0319761ed0 100644 --- a/cohttp/scripts/generate.ml +++ b/cohttp/scripts/generate.ml @@ -196,7 +196,7 @@ let output_type oc ~mli t = if i = 0 then append oc " [ %s%s" c.constr doc else append oc " | %s%s" c.constr doc) t.codes; - append oc " ] [@@deriving compare, sexp]"; + append oc " ] [@@deriving sexp]"; if mli then append oc "(** %s *)" (String.capitalize_ascii t.section); append oc "" @@ -204,11 +204,9 @@ 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 compare, sexp]"; + append oc "] [@@deriving sexp]"; append oc ""; - 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 "type status_code = [`Code of int | status ] [@@deriving sexp]"; append oc "" let iter fn s = List.iter (fun s -> List.iter fn s.codes) s @@ -284,7 +282,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 compare, sexp]"; + append oc "] [@@deriving sexp]"; append oc "" let output_gen_convert oc ~mli (name, typ, gens) = @@ -344,7 +342,6 @@ 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/cookie.ml b/cohttp/src/cookie.ml index 17ca9a43e3..89f1718c48 100644 --- a/cohttp/src/cookie.ml +++ b/cohttp/src/cookie.ml @@ -29,7 +29,14 @@ module Set_cookie_hdr = struct secure : bool; http_only : bool; } - [@@deriving fields, sexp] + [@@deriving sexp] + + let cookie t = t.cookie + let expiration t = t.expiration + let domain t = t.domain + let path t = t.path + let secure t = t.secure + let http_only t = t.http_only (* Does not check the contents of name or value for ';', ',', '\s', or name[0]='$' *) let make ?(expiration = `Session) ?path ?domain ?(secure = false) diff --git a/cohttp/src/cookie.mli b/cohttp/src/cookie.mli index 59c43102d1..70a0a8ef62 100644 --- a/cohttp/src/cookie.mli +++ b/cohttp/src/cookie.mli @@ -44,7 +44,7 @@ module Set_cookie_hdr : sig secure : bool; http_only : bool; } - [@@deriving fields, sexp] + [@@deriving sexp] (** A header which a server sends to a client to request that the client returns the cookie in future requests, under certain conditions. *) @@ -80,6 +80,8 @@ module Set_cookie_hdr : sig val secure : t -> bool (** Has the cookie's secure attribute been set? *) + + val http_only : t -> bool end module Cookie_hdr : sig diff --git a/cohttp/src/dune b/cohttp/src/dune index 0846994375..c115ca1e61 100644 --- a/cohttp/src/dune +++ b/cohttp/src/dune @@ -17,9 +17,8 @@ (public_name cohttp) (synopsis "Co-operative Client/Server HTTP library.") (preprocess - (pps ppx_compare ppx_fields_conv ppx_sexp_conv)) - (libraries ppx_compare.runtime-lib re stringext uri uri-sexp fieldslib - sexplib0 bytes base64)) + (pps ppx_sexp_conv)) + (libraries re stringext uri uri-sexp sexplib0 bytes base64)) (ocamllex accept_lexer) diff --git a/cohttp/src/link.ml b/cohttp/src/link.ml index dbf284df65..0343df62d7 100644 --- a/cohttp/src/link.ml +++ b/cohttp/src/link.ml @@ -119,8 +119,11 @@ end module Ext = struct type 'a t = { charset : Charset.t; language : Language.t; value : 'a } - [@@deriving sexp, fields] + [@@deriving sexp] + let charset t = t.charset + let language t = t.language + let value t = t.value let make ?(charset = "") ?(language = "") value = { charset; language; value } let map f x = { x with value = f x.value } end diff --git a/cohttp/src/request.ml b/cohttp/src/request.ml index 0368051b43..215086a090 100644 --- a/cohttp/src/request.ml +++ b/cohttp/src/request.ml @@ -14,7 +14,6 @@ * }}}*) -open Ppx_compare_lib.Builtin open Sexplib0.Sexp_conv type t = { @@ -25,8 +24,21 @@ type t = { version : Code.version; encoding : Transfer.encoding; } -[@@deriving compare, fields, sexp] - +[@@deriving sexp] + +let compare x y = + match Header.compare x.headers y.headers with + | 0 -> + let headers = Header.init () in + Stdlib.compare { x with headers } { y with headers } + | i -> i + +let headers t = t.headers +let meth t = t.meth +let scheme t = t.scheme +let resource t = t.resource +let version t = t.version +let encoding t = t.encoding let fixed_zero = Transfer.Fixed Int64.zero let guess_encoding ?(encoding = fixed_zero) headers = diff --git a/cohttp/src/response.ml b/cohttp/src/response.ml index b79e50d10f..b168ea7198 100644 --- a/cohttp/src/response.ml +++ b/cohttp/src/response.ml @@ -16,8 +16,6 @@ open Sexplib0.Sexp_conv -let compare_bool = Bool.compare - type t = { encoding : Transfer.encoding; headers : Header.t; @@ -25,7 +23,20 @@ type t = { status : Code.status_code; flush : bool; } -[@@deriving compare, fields, sexp] +[@@deriving sexp] + +let compare x y = + match Header.compare x.headers y.headers with + | 0 -> + let headers = Header.init () in + Stdlib.compare { x with headers } { y with headers } + | i -> i + +let headers t = t.headers +let encoding t = t.encoding +let version t = t.version +let status t = t.status +let flush t = t.flush let make ?(version = `HTTP_1_1) ?(status = `OK) ?(flush = false) ?(encoding = Transfer.Chunked) ?(headers = Header.init ()) () = diff --git a/cohttp/src/s.ml b/cohttp/src/s.ml index f25eb199c1..e09b15c719 100644 --- a/cohttp/src/s.ml +++ b/cohttp/src/s.ml @@ -86,7 +86,15 @@ module type Request = sig version : Code.version; (** HTTP version, usually 1.1 *) encoding : Transfer.encoding; (** transfer encoding of this HTTP request *) } - [@@deriving compare, fields, sexp] + [@@deriving sexp] + + val headers : t -> Header.t + val meth : t -> Code.meth + val scheme : t -> string option + val resource : t -> string + val version : t -> Code.version + val encoding : t -> Transfer.encoding + val compare : t -> t -> int val make : ?meth:Code.meth -> @@ -119,14 +127,15 @@ module type Response = sig status : Code.status_code; (** HTTP status code of the response *) flush : bool; } - [@@deriving compare, fields, sexp] - - (* The response creates by [make ~encoding ~headers ()] has an - encoding value determined from the content of [headers] or if no - proper header is present, using the value of [encoding]. Checked - headers are "content-lenght", "content-range" and - "transfer-encoding". The default value of [encoding] is - chunked. *) + [@@deriving sexp] + + val encoding : t -> Transfer.encoding + val headers : t -> Header.t + val version : t -> Code.version + val status : t -> Code.status_code + val flush : t -> bool + val compare : t -> t -> int + val make : ?version:Code.version -> ?status:Code.status_code -> @@ -135,6 +144,11 @@ module type Response = sig ?headers:Header.t -> unit -> t + (** The response creates by [make ~encoding ~headers ()] has an encoding value + determined from the content of [headers] or if no proper header is + present, using the value of [encoding]. Checked headers are + "content-lenght", "content-range" and "transfer-encoding". The default + value of [encoding] is chunked. *) end module type Body = sig diff --git a/cohttp/src/transfer.ml b/cohttp/src/transfer.ml index 19d14db827..d31a30f74b 100644 --- a/cohttp/src/transfer.ml +++ b/cohttp/src/transfer.ml @@ -16,9 +16,7 @@ open Sexplib0.Sexp_conv -let compare_int64 = Int64.compare - -type encoding = Chunked | Fixed of int64 | Unknown [@@deriving compare, sexp] +type encoding = Chunked | Fixed of int64 | Unknown [@@deriving sexp] type chunk = Chunk of string | Final_chunk of string | Done [@@deriving sexp] let string_of_encoding = function diff --git a/cohttp/src/transfer.mli b/cohttp/src/transfer.mli index cb97837885..63fda6c0b7 100644 --- a/cohttp/src/transfer.mli +++ b/cohttp/src/transfer.mli @@ -23,7 +23,7 @@ type encoding = | Chunked (** dynamic chunked encoding *) | Fixed of int64 (** fixed size content *) | Unknown (** unknown body size, which leads to best-effort *) -[@@deriving compare, sexp] +[@@deriving sexp] (** A chunk of body that also signals if there to more to arrive *) type chunk = diff --git a/cohttp/test/dune b/cohttp/test/dune index 4632550955..de9dd6bc91 100644 --- a/cohttp/test/dune +++ b/cohttp/test/dune @@ -1,6 +1,7 @@ (executable (name test_accept) (modules test_accept) + (forbidden_libraries base) (libraries cohttp alcotest fmt)) (rule @@ -12,6 +13,7 @@ (executable (name test_header) (modules test_header) + (forbidden_libraries base) (libraries cohttp alcotest fmt)) (rule @@ -23,6 +25,7 @@ (executable (name test_request) (modules test_request) + (forbidden_libraries base) (libraries cohttp alcotest fmt)) (rule @@ -34,6 +37,7 @@ (executable (name test_body) (modules test_body) + (forbidden_libraries base) (libraries cohttp alcotest fmt)) (rule