From 256366ceac6d3912b85c5bbdddb4ac65737773ca Mon Sep 17 00:00:00 2001 From: Danny Willems Date: Mon, 31 Oct 2016 17:42:32 +0100 Subject: [PATCH] Add prefix_and_path_of_t --- src/baselib/ocsigen_lib.ml | 16 ++++++++++++++++ src/baselib/ocsigen_lib.mli | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/src/baselib/ocsigen_lib.ml b/src/baselib/ocsigen_lib.ml index d645e32eb..56e6796fa 100644 --- a/src/baselib/ocsigen_lib.ml +++ b/src/baselib/ocsigen_lib.ml @@ -259,4 +259,20 @@ module Url = struct let split_path = Neturl.split_path + let prefix_and_path_of_t url = + let (https, host, port, _, path, _, _) = parse url in + let https_str = match https with + | None -> "" + | Some x -> if x then "https://" else "http://" + in + let host_str = match host with + | None -> "" + | Some x -> x + in + let port_str = match port with + | None -> "" + | Some x -> string_of_int x + in + (https_str ^ host_str ^ ":" ^ port_str, path) + end diff --git a/src/baselib/ocsigen_lib.mli b/src/baselib/ocsigen_lib.mli index 6f2905e3e..f8a9c6e28 100644 --- a/src/baselib/ocsigen_lib.mli +++ b/src/baselib/ocsigen_lib.mli @@ -78,4 +78,13 @@ module Url : sig (** alias of (Ocamlnet) [Neturl.split_path] *) val split_path : string -> string list + (** [prefix_and_path_of_t url] splits [url] in a couple [(prefix, path)] where + [prefix] is ["http(s)://host:port"] and [path] is the path as [string list] + + Example: [prefix_and_path_of_t "http://ocsigen.org:80/tuto/manual"] + returns [("http://ocsigen.org:80", ["tuto", "manual"])]. + *) + val prefix_and_path_of_t : + string -> + string * string list end