Skip to content

Commit e6c2509

Browse files
author
Jan Rochel
authored
Merge pull request #113 from dannywillems/prefix_and_path_of_t
Add prefix_and_path_of_t
2 parents d67cb05 + 256366c commit e6c2509

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
@@ -303,4 +303,20 @@ module Url = struct
303303

304304
let split_path = Neturl.split_path
305305

306+
let prefix_and_path_of_t url =
307+
let (https, host, port, _, path, _, _) = parse url in
308+
let https_str = match https with
309+
| None -> ""
310+
| Some x -> if x then "https://" else "http://"
311+
in
312+
let host_str = match host with
313+
| None -> ""
314+
| Some x -> x
315+
in
316+
let port_str = match port with
317+
| None -> ""
318+
| Some x -> string_of_int x
319+
in
320+
(https_str ^ host_str ^ ":" ^ port_str, path)
321+
306322
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)