From f6c14a7fe130068bbf9337f322aceea623fb529d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 31 May 2015 20:03:22 -0400 Subject: [PATCH 1/6] add pp_hum printers to header/request/response --- lib/header.ml | 3 +++ lib/header.mli | 3 +++ lib/request.ml | 3 +++ lib/request.mli | 3 +++ lib/response.ml | 3 +++ lib/response.mli | 3 +++ 6 files changed, 18 insertions(+) diff --git a/lib/header.ml b/lib/header.ml index 0f0cdad850..5fab628e73 100644 --- a/lib/header.ml +++ b/lib/header.ml @@ -248,6 +248,7 @@ let connection h = | Some x -> Some (`Unknown x) | x -> None +open Sexplib open Sexplib.Std open Sexplib.Conv @@ -256,3 +257,5 @@ let sexp_of_t t = let t_of_sexp s = of_list (list_of_sexp (pair_of_sexp string_of_sexp string_of_sexp) s) + +let pp_hum ppf h = Format.fprintf ppf "%s" (h |> sexp_of_t |> Sexp.to_string) diff --git a/lib/header.mli b/lib/header.mli index 98c3369a4c..5b4bd54814 100644 --- a/lib/header.mli +++ b/lib/header.mli @@ -105,3 +105,6 @@ val prepend_user_agent : t -> string -> t "User-Agent" field (if any). *) val connection : t -> [`Keep_alive | `Close | `Unknown of string] option + +(** Human-readable output, used by the toplevel printer *) +val pp_hum : Format.formatter -> t -> unit diff --git a/lib/request.ml b/lib/request.ml index 3ebda9b678..128a9542e8 100644 --- a/lib/request.ml +++ b/lib/request.ml @@ -70,6 +70,9 @@ let make_for_client ?headers ?(chunked=true) ?(body_length=Int64.zero) meth uri in make ~meth ~encoding ?headers uri +let pp_hum ppf r = + Format.fprintf ppf "%s" (r |> sexp_of_t |> Sexplib.Sexp.to_string) + type tt = t module Make(IO : S.IO) = struct type t = tt diff --git a/lib/request.mli b/lib/request.mli index f840baf044..6125b2dfe9 100644 --- a/lib/request.mli +++ b/lib/request.mli @@ -27,6 +27,9 @@ serializers to convert to-and-from an {!Core.Std.Sexp.t}. *) include S.Request +(** Human-readable output, used by the toplevel printer *) +val pp_hum : Format.formatter -> t -> unit + (** Functor to construct the IO-specific HTTP request handling functions *) module Make(IO : S.IO) : S.Http_io with type t = t diff --git a/lib/response.ml b/lib/response.ml index 8e5874dde6..740204c51a 100644 --- a/lib/response.ml +++ b/lib/response.ml @@ -29,6 +29,9 @@ let make ?(version=`HTTP_1_1) ?(status=`OK) ?(flush=false) ?(encoding=Transfer.C let headers = match headers with None -> Header.init () |Some h -> h in { encoding; headers; version; flush; status } +let pp_hum ppf r = + Format.fprintf ppf "%s" (r |> sexp_of_t |> Sexplib.Sexp.to_string) + type tt = t module Make(IO : S.IO) = struct type t = tt diff --git a/lib/response.mli b/lib/response.mli index 55e5cd44e1..2c5f8cb79a 100644 --- a/lib/response.mli +++ b/lib/response.mli @@ -29,6 +29,9 @@ serializers to convert to-and-from an {!Core.Std.Sexp.t}. *) include S.Response +(** Human-readable output, used by the toplevel printer *) +val pp_hum : Format.formatter -> t -> unit + (** Functor to construct the IO-specific response handling function *) module Make(IO : S.IO) : S.Http_io with type t = t From 71cc829bb63277d62c82314322724b617398ddc7 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 31 May 2015 20:04:28 -0400 Subject: [PATCH 2/6] add Cohttp_top module to install toplevel printers --- top/cohttp_top.ml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 top/cohttp_top.ml diff --git a/top/cohttp_top.ml b/top/cohttp_top.ml new file mode 100644 index 0000000000..04dc81059f --- /dev/null +++ b/top/cohttp_top.ml @@ -0,0 +1,20 @@ +let printers = [ "Cohttp.Header.pp_hum" + ; "Cohttp.Request.pp_hum" + ; "Cohttp.Response.pp_hum" ] + +let eval_string + ?(print_outcome = false) ?(err_formatter = Format.err_formatter) str = + let lexbuf = Lexing.from_string str in + let phrase = !Toploop.parse_toplevel_phrase lexbuf in + Toploop.execute_phrase print_outcome err_formatter phrase + +let rec install_printers = function + | [] -> true + | printer :: printers -> + let cmd = Printf.sprintf "#install_printer %s;;" printer in + eval_string cmd && install_printers printers + +let () = + if not (install_printers printers) then + Format.eprintf "Problem installing Cohttp-printers@." + From 4a867c54574565ce355358615032d91feaf8e0fc Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 31 May 2015 20:05:21 -0400 Subject: [PATCH 3/6] add cohttp.top lib to install printers --- _oasis | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/_oasis b/_oasis index 2140dd76f4..5326ff1bf5 100644 --- a/_oasis +++ b/_oasis @@ -44,6 +44,15 @@ Library cohttp_test Modules: Cohttp_test BuildDepends: cohttp, oUnit +Library cohttp_top + Install: true + Path: top + Findlibname: top + FindlibParent: cohttp + XMETARequires: cohttp + BuildDepends: compiler-libs.toplevel + Modules: Cohttp_top + Flag all Description: build everything that is possible Default: false From 4873bd6dac489e79a11bc93fd5fe9083b9ff6372 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 31 May 2015 20:05:48 -0400 Subject: [PATCH 4/6] regenerate oasis --- _tags | 5 ++++- lib/META | 13 ++++++++++++- myocamlbuild.ml | 5 +++-- setup.ml | 37 ++++++++++++++++++++++++++++++++++--- top/cohttp_top.mldylib | 4 ++++ top/cohttp_top.mllib | 4 ++++ 6 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 top/cohttp_top.mldylib create mode 100644 top/cohttp_top.mllib diff --git a/_tags b/_tags index 241231fdd9..9435c96626 100644 --- a/_tags +++ b/_tags @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: 811b48ecb494c9283414e38214743062) +# DO NOT EDIT (digest: e44c7776ad3e33b5f7a5cacdf7e3cf51) # Ignore VCS directories, you can use the same kind of rule outside # OASIS_START/STOP if you want to exclude directories that contains # useless stuff for the build process @@ -49,6 +49,9 @@ true: annot, bin_annot : pkg_uri : pkg_uri.services : use_cohttp +# Library cohttp_top +"top/cohttp_top.cmxs": use_cohttp_top +: pkg_compiler-libs.toplevel # Library cohttp_lwt "lwt/cohttp_lwt.cmxs": use_cohttp_lwt # Library cohttp_lwt_unix diff --git a/lib/META b/lib/META index 6bb3083571..8439fae0ce 100644 --- a/lib/META +++ b/lib/META @@ -1,5 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: 0993413eb2018c7116a8e1ceec9b45f9) +# DO NOT EDIT (digest: 43144d443f8df44ab09d0fc9136bc5d0) version = "0.17.2" description = "HTTP library for Lwt, Async, JavaScript and Mirage" requires = @@ -9,6 +9,17 @@ archive(byte, plugin) = "cohttp.cma" archive(native) = "cohttp.cmxa" archive(native, plugin) = "cohttp.cmxs" exists_if = "cohttp.cma" +package "top" ( + version = "0.17.2" + description = "HTTP library for Lwt, Async, JavaScript and Mirage" + requires = "cohttp" + archive(byte) = "cohttp_top.cma" + archive(byte, plugin) = "cohttp_top.cma" + archive(native) = "cohttp_top.cmxa" + archive(native, plugin) = "cohttp_top.cmxs" + exists_if = "cohttp_top.cma" +) + package "test" ( version = "0.17.2" description = "HTTP library for Lwt, Async, JavaScript and Mirage" diff --git a/myocamlbuild.ml b/myocamlbuild.ml index d8f7f5b03f..2f87a60f3d 100644 --- a/myocamlbuild.ml +++ b/myocamlbuild.ml @@ -1,5 +1,5 @@ (* OASIS_START *) -(* DO NOT EDIT (digest: ff6dfa24b5c9bce29b3a58476f2a0337) *) +(* DO NOT EDIT (digest: 263a4e4510a24a3732c5cc97c5ccec8d) *) module OASISGettext = struct (* # 22 "src/oasis/OASISGettext.ml" *) @@ -611,6 +611,7 @@ let package_default = [ ("cohttp", ["lib"], []); ("cohttp_test", ["lib"], []); + ("cohttp_top", ["top"], []); ("cohttp_lwt", ["lwt"], []); ("cohttp_lwt_unix", ["lwt"], []); ("cohttp_lwt_xhr", ["js"], []); @@ -636,6 +637,6 @@ let conf = {MyOCamlbuildFindlib.no_automatic_syntax = false} let dispatch_default = MyOCamlbuildBase.dispatch_default conf package_default;; -# 640 "myocamlbuild.ml" +# 641 "myocamlbuild.ml" (* OASIS_STOP *) Ocamlbuild_plugin.dispatch dispatch_default;; diff --git a/setup.ml b/setup.ml index 1d80772070..3a04aa0d44 100644 --- a/setup.ml +++ b/setup.ml @@ -1,7 +1,7 @@ (* setup.ml generated for the first time by OASIS v0.4.5 *) (* OASIS_START *) -(* DO NOT EDIT (digest: 2803c6b233c82e6bd6bdb06949376864) *) +(* DO NOT EDIT (digest: ddfca6121be164d9f95dd91f3e7db714) *) (* Regenerated by OASIS v0.4.5 Visit http://oasis.forge.ocamlcore.org for more information and @@ -7200,6 +7200,37 @@ let setup_t = lib_findlib_name = Some "test"; lib_findlib_containers = [] }); + Library + ({ + cs_name = "cohttp_top"; + cs_data = PropList.Data.create (); + cs_plugin_data = [] + }, + { + bs_build = [(OASISExpr.EBool true, true)]; + bs_install = [(OASISExpr.EBool true, true)]; + bs_path = "top"; + bs_compiled_object = Best; + bs_build_depends = + [FindlibPackage ("compiler-libs.toplevel", None)]; + bs_build_tools = [ExternalTool "ocamlbuild"]; + bs_c_sources = []; + bs_data_files = []; + bs_ccopt = [(OASISExpr.EBool true, [])]; + bs_cclib = [(OASISExpr.EBool true, [])]; + bs_dlllib = [(OASISExpr.EBool true, [])]; + bs_dllpath = [(OASISExpr.EBool true, [])]; + bs_byteopt = [(OASISExpr.EBool true, [])]; + bs_nativeopt = [(OASISExpr.EBool true, [])] + }, + { + lib_modules = ["Cohttp_top"]; + lib_pack = false; + lib_internal_modules = []; + lib_findlib_parent = Some "cohttp"; + lib_findlib_name = Some "top"; + lib_findlib_containers = [] + }); Flag ({ cs_name = "all"; @@ -8856,7 +8887,7 @@ let setup_t = }; oasis_fn = Some "_oasis"; oasis_version = "0.4.5"; - oasis_digest = Some "$\137O6@C\018¶\154%-aåmÒ´"; + oasis_digest = Some "_\141¸\155öþa\004E\133¨NÍ\011-\128"; oasis_exec = None; oasis_setup_args = []; setup_update = false @@ -8864,6 +8895,6 @@ let setup_t = let setup () = BaseSetup.setup setup_t;; -# 8868 "setup.ml" +# 8899 "setup.ml" (* OASIS_STOP *) let () = setup ();; diff --git a/top/cohttp_top.mldylib b/top/cohttp_top.mldylib new file mode 100644 index 0000000000..d917878aca --- /dev/null +++ b/top/cohttp_top.mldylib @@ -0,0 +1,4 @@ +# OASIS_START +# DO NOT EDIT (digest: 2f82f537ac3c3eae3961f1001930e9e6) +Cohttp_top +# OASIS_STOP diff --git a/top/cohttp_top.mllib b/top/cohttp_top.mllib new file mode 100644 index 0000000000..d917878aca --- /dev/null +++ b/top/cohttp_top.mllib @@ -0,0 +1,4 @@ +# OASIS_START +# DO NOT EDIT (digest: 2f82f537ac3c3eae3961f1001930e9e6) +Cohttp_top +# OASIS_STOP From 457eb5f23b725ef2639369c723ad0b942f5d15a4 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 31 May 2015 20:06:02 -0400 Subject: [PATCH 5/6] add compiler libs to .merlin --- .merlin | 1 + 1 file changed, 1 insertion(+) diff --git a/.merlin b/.merlin index b8a29bccd0..3e169c5449 100644 --- a/.merlin +++ b/.merlin @@ -32,6 +32,7 @@ PKG cmdliner PKG js_of_ocaml PKG magic-mime PKG alcotest +PKG compiler-libs.toplevel B _build/ B _build/lwt From 2c9cdd8fbc1744c4e8be50c2f38360fbccefb89d Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 31 May 2015 20:18:45 -0400 Subject: [PATCH 6/6] Sexp.to_string -> Sexp.to_string_hum --- lib/header.ml | 3 ++- lib/request.ml | 2 +- lib/response.ml | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/header.ml b/lib/header.ml index 5fab628e73..9a57bfa1f9 100644 --- a/lib/header.ml +++ b/lib/header.ml @@ -258,4 +258,5 @@ let sexp_of_t t = let t_of_sexp s = of_list (list_of_sexp (pair_of_sexp string_of_sexp string_of_sexp) s) -let pp_hum ppf h = Format.fprintf ppf "%s" (h |> sexp_of_t |> Sexp.to_string) +let pp_hum ppf h = + Format.fprintf ppf "%s" (h |> sexp_of_t |> Sexp.to_string_hum) diff --git a/lib/request.ml b/lib/request.ml index 128a9542e8..e78e9ebd23 100644 --- a/lib/request.ml +++ b/lib/request.ml @@ -71,7 +71,7 @@ let make_for_client ?headers ?(chunked=true) ?(body_length=Int64.zero) meth uri make ~meth ~encoding ?headers uri let pp_hum ppf r = - Format.fprintf ppf "%s" (r |> sexp_of_t |> Sexplib.Sexp.to_string) + Format.fprintf ppf "%s" (r |> sexp_of_t |> Sexplib.Sexp.to_string_hum) type tt = t module Make(IO : S.IO) = struct diff --git a/lib/response.ml b/lib/response.ml index 740204c51a..f6c36682fc 100644 --- a/lib/response.ml +++ b/lib/response.ml @@ -30,7 +30,7 @@ let make ?(version=`HTTP_1_1) ?(status=`OK) ?(flush=false) ?(encoding=Transfer.C { encoding; headers; version; flush; status } let pp_hum ppf r = - Format.fprintf ppf "%s" (r |> sexp_of_t |> Sexplib.Sexp.to_string) + Format.fprintf ppf "%s" (r |> sexp_of_t |> Sexplib.Sexp.to_string_hum) type tt = t module Make(IO : S.IO) = struct