Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency to base #745

Merged
merged 3 commits into from
Feb 6, 2021
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cohttp-lwt-unix/test/test_parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 () =
Expand Down
5 changes: 1 addition & 4 deletions cohttp.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
11 changes: 4 additions & 7 deletions cohttp/scripts/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,17 @@ 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 ""

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
Expand Down Expand Up @@ -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) =
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion cohttp/src/cookie.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion cohttp/src/cookie.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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. *)

Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions cohttp/src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion cohttp/src/link.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 15 additions & 3 deletions cohttp/src/request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*
}}}*)

open Ppx_compare_lib.Builtin
open Sexplib0.Sexp_conv

type t = {
Expand All @@ -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 =
Expand Down
17 changes: 14 additions & 3 deletions cohttp/src/response.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,27 @@

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 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 ()) () =
Expand Down
32 changes: 23 additions & 9 deletions cohttp/src/s.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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 ->
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions cohttp/src/transfer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cohttp/src/transfer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 4 additions & 0 deletions cohttp/test/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(executable
(name test_accept)
(modules test_accept)
(forbidden_libraries base)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update dune lower bound to use this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I've just bumped it in the opam file (the dune-project file was already using the right version)

(libraries cohttp alcotest fmt))

(rule
Expand All @@ -12,6 +13,7 @@
(executable
(name test_header)
(modules test_header)
(forbidden_libraries base)
(libraries cohttp alcotest fmt))

(rule
Expand All @@ -23,6 +25,7 @@
(executable
(name test_request)
(modules test_request)
(forbidden_libraries base)
(libraries cohttp alcotest fmt))

(rule
Expand All @@ -34,6 +37,7 @@
(executable
(name test_body)
(modules test_body)
(forbidden_libraries base)
(libraries cohttp alcotest fmt))

(rule
Expand Down