···
let open Cohttp_lwt_unix in
let headers = Header.add_list (Header.init ()) headers in
402
+
(* Debug: print request details *)
403
+
Printf.printf "\n===== HTTP REQUEST =====\n";
404
+
Printf.printf "URI: %s\n" (Uri.to_string uri);
405
+
Printf.printf "METHOD: POST\n";
406
+
Printf.printf "HEADERS:\n";
407
+
Header.iter (fun k v -> Printf.printf " %s: %s\n" k v) headers;
408
+
Printf.printf "BODY:\n%s\n" body;
409
+
Printf.printf "======================\n\n";
let* resp, body = Client.post ~headers ~body:(Cohttp_lwt.Body.of_string body) uri in
let* body_str = Cohttp_lwt.Body.to_string body in
let status = Response.status resp |> Code.code_of_status in
417
+
(* Debug: print response details *)
418
+
Printf.printf "\n===== HTTP RESPONSE =====\n";
419
+
Printf.printf "STATUS: %d\n" status;
420
+
Printf.printf "HEADERS:\n";
421
+
Response.headers resp |> Header.iter (fun k v -> Printf.printf " %s: %s\n" k v);
422
+
Printf.printf "BODY:\n%s\n" body_str;
423
+
Printf.printf "========================\n\n";
if status >= 200 && status < 300 then
Lwt.return (Error (HTTP_error (status, body_str))))
410
-
(fun e -> Lwt.return (Error (Connection_error (Printexc.to_string e))))
430
+
let error_msg = Printexc.to_string e in
431
+
Printf.printf "\n===== HTTP ERROR =====\n%s\n======================\n\n" error_msg;
432
+
Lwt.return (Error (Connection_error error_msg)))
(** Make a raw JMAP API request
···
(* API token (bearer authentication) *)
"Bearer " ^ config.authentication_token
448
+
Printf.printf "Using authorization header: %s\n" auth_header;
("Content-Type", "application/json");
("Content-Length", string_of_int (String.length body));
···
let get_session uri ?username ?authentication_token ?api_token () =
match (username, authentication_token, api_token) with
501
-
| (Some u, Some t, _) -> [
502
-
("Content-Type", "application/json");
503
-
("Authorization", "Basic " ^ Base64.encode_string (u ^ ":" ^ t))
505
-
| (_, _, Some token) -> [
506
-
("Content-Type", "application/json");
507
-
("Authorization", "Bearer " ^ token)
524
+
| (Some u, Some t, _) ->
525
+
let auth = "Basic " ^ Base64.encode_string (u ^ ":" ^ t) in
526
+
Printf.printf "Session using Basic auth: %s\n" auth;
528
+
("Content-Type", "application/json");
529
+
("Authorization", auth)
531
+
| (_, _, Some token) ->
532
+
let auth = "Bearer " ^ token in
533
+
Printf.printf "Session using Bearer auth: %s\n" auth;
535
+
("Content-Type", "application/json");
536
+
("Authorization", auth)
| _ -> [("Content-Type", "application/json")]