Skip to content

Commit c31aed9

Browse files
committed
debug response headers
1 parent 925d21c commit c31aed9

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/server/cohttp/ezAPIServerCohttp.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ let dispatch ?allow_origin ?allow_headers ?allow_methods ?allow_credentials
9898
?allow_methods ?allow_credentials ?origin resp_headers in
9999
let status = Code.status_of_code code in
100100
debug ~v:(if code >= 200 && code < 300 then 1 else 0) "Reply computed to %S: %d" path_str code;
101+
debugf ~v:4 (fun () ->
102+
List.iter (fun (name, value) -> EzDebug.printf " %s: %s" name value) headers
103+
);
101104
debugf ~v:3 (fun () ->
102105
let content_type = List.assoc_opt "content-type" resp_headers in
103106
if body <> "" && (content_type = Some "application/json" || content_type = Some "text/plain") then

src/server/httpaf/ezAPIServerHttpAf.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,18 @@ let connection_handler ?catch ?allow_origin ?allow_headers ?allow_methods
7676
| `http {Answer.code; body; headers=resp_headers} ->
7777
let status = Status.unsafe_of_code code in
7878
debug ~v:(if code >= 200 && code < 300 then 1 else 0) "Reply computed to %S: %d" path_str code;
79-
debugf ~v:3 (fun () ->
80-
let content_type = List.assoc_opt "content-type" resp_headers in
81-
if body <> "" && (content_type = Some "application/json" || content_type = Some "text/plain") then
82-
EzDebug.printf "Reply content:\n%s" body);
8379
let origin = match allow_origin with
8480
| Some `origin -> StringMap.find_opt "origin" headers
8581
| _ -> None in
8682
let headers = merge_headers_with_default ?allow_origin ?allow_headers
8783
?allow_methods ?allow_credentials ?origin resp_headers in
84+
debugf ~v:4 (fun () ->
85+
List.iter (fun (name, value) -> EzDebug.printf " %s: %s" name value) headers
86+
);
87+
debugf ~v:3 (fun () ->
88+
let content_type = List.assoc_opt "content-type" resp_headers in
89+
if body <> "" && (content_type = Some "application/json" || content_type = Some "text/plain") then
90+
EzDebug.printf "Reply content:\n%s" body);
8891
let headers = Headers.of_list headers in
8992
let body = Option.fold ~none:body ~some:(fun f -> body ^ f) footer in
9093
let len = String.length body in

src/server/httpun/ezAPIServerHttpun.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,18 @@ let connection_handler ?catch ?allow_origin ?allow_headers ?allow_methods
7777
| `http {Answer.code; body; headers=resp_headers} ->
7878
let status = Status.unsafe_of_code code in
7979
debug ~v:(if code >= 200 && code < 300 then 1 else 0) "Reply computed to %S: %d" path_str code;
80-
debugf ~v:3 (fun () ->
81-
let content_type = List.assoc_opt "content-type" resp_headers in
82-
if body <> "" && (content_type = Some "application/json" || content_type = Some "text/plain") then
83-
EzDebug.printf "Reply content:\n%s" body);
8480
let origin = match allow_origin with
8581
| Some `origin -> StringMap.find_opt "origin" headers
8682
| _ -> None in
8783
let headers = merge_headers_with_default ?allow_origin ?allow_headers
8884
?allow_methods ?allow_credentials ?origin resp_headers in
85+
debugf ~v:4 (fun () ->
86+
List.iter (fun (name, value) -> EzDebug.printf " %s: %s" name value) headers
87+
);
88+
debugf ~v:3 (fun () ->
89+
let content_type = List.assoc_opt "content-type" resp_headers in
90+
if body <> "" && (content_type = Some "application/json" || content_type = Some "text/plain") then
91+
EzDebug.printf "Reply content:\n%s" body);
8992
let headers = Headers.of_list headers in
9093
let body = Option.fold ~none:body ~some:(fun f -> body ^ f) footer in
9194
let len = String.length body in

0 commit comments

Comments
 (0)