diff --git a/lib/uri.ml b/lib/uri.ml index 83b3807..d44ca8e 100644 --- a/lib/uri.ml +++ b/lib/uri.ml @@ -438,6 +438,12 @@ module Path = struct ) "" buf p; Pct.cast_encoded (Buffer.contents buf) + let decoded_of_path p = + let len = List.fold_left (fun c tok -> String.length tok + c) 0 p in + let buf = Buffer.create len in + iter_concat (fun buf s -> Buffer.add_string buf s) "" buf p; + Pct.cast_decoded (Buffer.contents buf) + (* Subroutine for resolve *) let merge bhost bpath relpath = match bhost, List.rev bpath with @@ -448,6 +454,7 @@ end let path_of_encoded = Path.path_of_encoded let encoded_of_path ?scheme ~component = Path.encoded_of_path ?scheme ~component +let decoded_of_path = Path.decoded_of_path (* Query string handling, to and from an assoc list of key/values *) module Query = struct @@ -754,6 +761,8 @@ let with_path uri path = | None, _ | Some _, "/"::_ | Some _, [] -> { uri with path=path } | Some _, _ -> { uri with path="/"::path } +let path_unencoded uri = Pct.uncast_decoded (decoded_of_path uri.path) + let fragment uri = get_decoded_opt uri.fragment let with_fragment uri = function diff --git a/lib/uri.mli b/lib/uri.mli index aec6204..de2035b 100644 --- a/lib/uri.mli +++ b/lib/uri.mli @@ -211,6 +211,9 @@ val path : ?pct_encoder:pct_encoder -> t -> string (** Get the encoded path and query components of a URI *) val path_and_query : t -> string +(** Get the unencoded path component of a URI *) +val path_unencoded : t -> string + (** Replace the path URI with the supplied encoded path. If a host is present in the supplied URI, the path is made absolute but not resolved. If the path is empty, the path component is removed.