Skip to content

Commit

Permalink
server debug: print only if content
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtori committed Nov 29, 2024
1 parent 93da38a commit 47c9389
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/server/cohttp/ezAPIServerCohttp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let dispatch ?allow_origin ?allow_headers ?allow_methods ?allow_credentials
let meth = meth_from_cohttp req in
Cohttp_lwt.Body.to_string body >>= fun body ->
let ws = WsCohttp.ws req in
debug ~v:2 "Request content:\n%s" body;
if body <> "" then debug ~v:2 "Request content:\n%s" body;
Lwt.catch (fun () -> handle ~ws ?meth ?content_type s.server_kind r path body)
(fun exn ->
EzDebug.printf "In %s: exception %s" path_str @@ Printexc.to_string exn;
Expand All @@ -96,7 +96,7 @@ let dispatch ?allow_origin ?allow_headers ?allow_methods ?allow_credentials
?allow_methods ?allow_credentials ?origin resp_headers in
let status = Code.status_of_code code in
debug ~v:(if code >= 200 && code < 300 then 1 else 0) "Reply computed to %S: %d" path_str code;
debug ~v:3 "Reply content:\n%s" body;
if body <> "" then debug ~v:3 "Reply content:\n%s" body;
let headers = Header.of_list headers in
Server.respond_string ~headers ~status ~body () >|= fun (r, b) ->
`Response (r, b)
Expand Down
4 changes: 2 additions & 2 deletions src/server/httpaf/ezAPIServerHttpAf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ let connection_handler ?allow_origin ?allow_headers ?allow_methods
Lwt.async @@ fun () ->
read_body (Reqd.request_body reqd) >>= fun body ->
let ws = WsHttpaf.ws reqd fd in
debug ~v:2 "Request content:\n%s" body;
if body <> "" then debug ~v:2 "Request content:\n%s" body;
Lwt.catch
(fun () -> handle ~ws ?meth ?content_type s.server_kind r path body)
(fun exn ->
Expand All @@ -277,7 +277,7 @@ let connection_handler ?allow_origin ?allow_headers ?allow_methods
| `http {Answer.code; body; headers=resp_headers} ->
let status = Status.unsafe_of_code code in
debug ~v:(if code = 200 then 1 else 0) "Reply computed to %S: %d" path_str code;
debug ~v:3 "Reply content:\n%s" body;
if body <> "" then debug ~v:3 "Reply content:\n%s" body;
let origin = match allow_origin with
| Some `origin -> StringMap.find_opt "origin" headers
| _ -> None in
Expand Down

0 comments on commit 47c9389

Please sign in to comment.