From 37bb814c27548b5c031cd52193ba50df55ef6fd9 Mon Sep 17 00:00:00 2001 From: Christian Lindig Date: Fri, 24 May 2024 10:34:24 +0100 Subject: [PATCH] CP-49647 use URI for newcli.ml Signed-off-by: Christian Lindig --- ocaml/xe-cli/newcli.ml | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/ocaml/xe-cli/newcli.ml b/ocaml/xe-cli/newcli.ml index 6d8a55590d4..6768c413c73 100644 --- a/ocaml/xe-cli/newcli.ml +++ b/ocaml/xe-cli/newcli.ml @@ -131,15 +131,23 @@ let rec read_rest_of_headers ic = [] let parse_url url = - if String.startswith "https://" url then - let stripped = end_of_string url (String.length "https://") in - let host, rest = - let l = String.split '/' stripped in - (List.hd l, List.tl l) - in - (host, "/" ^ String.concat "/" rest) - else - (!xapiserver, url) + let parse uri = + let ( let* ) = Option.bind in + let* scheme = Uri.scheme uri in + let* host = Uri.host uri in + let path = Uri.path_and_query uri in + Some (scheme, host, path) + in + match parse (Uri.of_string url) with + | Some ("https", host, path) -> + (host, path) + | _ -> + debug "%s: could not parse '%s'" __FUNCTION__ url ; + (!xapiserver, url) + | exception e -> + debug "%s: could not parse '%s': %s" __FUNCTION__ url + (Printexc.to_string e) ; + (!xapiserver, url) (* Read the password file *) let read_pwf () =