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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## current

- lwt_jsoo: Use logs for the warnings and document it (mseri #776)
- lwt: Use logs to warn users about leaked bodies and document it (mseri #771)
- lwt, lwt_unix: Improve use of logs and the documentation, fix bug in the Debug.enable_debug function (mseri #772)
- lwt_jsoo: Fix exception on connection errors in chrome (mefyl #761)
Expand Down
1 change: 1 addition & 0 deletions cohttp-lwt-jsoo.opam
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ depends: [
"dune" {>= "2.0"}
"cohttp" {= version}
"cohttp-lwt" {= version}
"logs"
"lwt" {>= "3.0.0"}
"lwt_ppx" {with-test}
"conf-npm" {with-test}
Expand Down
12 changes: 7 additions & 5 deletions cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ module IO = Cohttp_lwt__String_io
module Header_io = Cohttp__Header_io.Make (IO)

module Body_builder (P : Params) = struct
let src = Logs.Src.create "cohttp.lwt.jsoo" ~doc:"Cohttp Lwt JSOO module"

module Log = (val Logs.src_log src : Logs.LOG)

(* perform the body transfer in chunks from string. *)
let chunked_body_str text =
let body_len = text##.length in
Expand Down Expand Up @@ -109,16 +113,14 @@ module Body_builder (P : Params) = struct
in
match xhr_response_supported with
| true when Js.Opt.return xml##.response == Js.null ->
Firebug.console##log
(Js.string "XHR Response is null; using empty string");
Log.warn (fun m -> m "XHR Response is null; using empty string");
`String (Js.string "")
| true ->
Js.Opt.case
(File.CoerceTo.arrayBuffer xml##.response)
(fun () ->
Firebug.console##log
(Js.string
"XHR Response is not an arrayBuffer; using responseText");
Log.warn (fun m ->
m "XHR Response is not an arrayBuffer; using responseText");
respText ())
(fun ab -> `ArrayBuffer ab)
| false -> respText ()
Expand Down
11 changes: 10 additions & 1 deletion cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.mli
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@
*
}}}*)

(** HTTP client for JavaScript using XMLHttpRequest. *)
(** {1 HTTP client for JavaScript using XMLHttpRequest.}

The {!Logs} source name for this module's logger is ["cohttp.lwt.jsoo"]. To
log the current warnings using the browser's console log, you can write a
custom reporter or use:

{[
let reporter = Logs_browser.console_reporter () in
Logs.set_reporter reporter
]} *)

(** Configuration parameters for the XmlHttpRequest engines *)
module type Params = sig
Expand Down
2 changes: 1 addition & 1 deletion cohttp-lwt-jsoo/src/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
(synopsis "XHR/Lwt based http client")
(preprocess
(pps js_of_ocaml-ppx))
(libraries js_of_ocaml cohttp-lwt))
(libraries js_of_ocaml cohttp-lwt logs))