Skip to content

Commit 256366c

Browse files
committed
Add prefix_and_path_of_t
1 parent 7b9e447 commit 256366c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/baselib/ocsigen_lib.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,20 @@ module Url = struct
259259

260260
let split_path = Neturl.split_path
261261

262+
let prefix_and_path_of_t url =
263+
let (https, host, port, _, path, _, _) = parse url in
264+
let https_str = match https with
265+
| None -> ""
266+
| Some x -> if x then "https://" else "http://"
267+
in
268+
let host_str = match host with
269+
| None -> ""
270+
| Some x -> x
271+
in
272+
let port_str = match port with
273+
| None -> ""
274+
| Some x -> string_of_int x
275+
in
276+
(https_str ^ host_str ^ ":" ^ port_str, path)
277+
262278
end

src/baselib/ocsigen_lib.mli

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,13 @@ module Url : sig
7878
(** alias of (Ocamlnet) [Neturl.split_path] *)
7979
val split_path : string -> string list
8080

81+
(** [prefix_and_path_of_t url] splits [url] in a couple [(prefix, path)] where
82+
[prefix] is ["http(s)://host:port"] and [path] is the path as [string list]
83+
84+
Example: [prefix_and_path_of_t "http://ocsigen.org:80/tuto/manual"]
85+
returns [("http://ocsigen.org:80", ["tuto", "manual"])].
86+
*)
87+
val prefix_and_path_of_t :
88+
string ->
89+
string * string list
8190
end

0 commit comments

Comments
 (0)