Module Http.Path

Paths.

type t = path

The type for absolute URI paths. See path.

val drop_prefix : path -> path -> path

drop_prefix pre p drops prefix pre from p. If pre is not a prefix of p this is p.

TODO talk about final "".

val undot_and_compress : path -> path

undot_and_compress p removes "." and ".." according to the RFC3986 algorithm and suppresses non final empty "" segments.

val to_undotted_filepath : path -> (string, string) Stdlib.result

to_undotted_filepath p is an absolute filepath for undot_and_compress p. It returns "/". Errors if any of the path segments contains a stray slash or backslash. The result always uses / as a directory separator regardless of the platform.

val prefix_filepath : string -> string -> string

prefix_filepath p0 p1 prefixes p1 by p0 avoiding producing empty segs.

Converting

val encode : path -> string

encode p encodes an absolute-path for p as follows:

  1. In each segment percent-encode any byte that is not unreserved, sub-delims, ':' or '@' to produce a valid URI segment.
  2. Prepends each segment with a '/'.
  3. Concatenate the result.

The empty list is special cased and yields "". path_to_undotted_filepath to convert paths to file paths.

Here are a few examples:

  • decode [] = ""
  • decode [""] = "/"
  • decode [""; ""] = "//"
  • decode ["a";"b";"c"] = "/a/b/c"
  • decode ["a";"b";"";"c";] = "/a/b//c"
  • decode ["a";"b";"c";""] = "/a/b/c/"
  • decode ["a";"b";"c";" "] = "/a/b/c/%20"
  • decode ["a";"b";"c";"";""] = "/a/b/c//"
  • decode ["a"; "b/"; "c"] = "/a/b%2F/c"
  • decode ["r\xC3\xC9volte"] = "/r%C3%C9volte"
  • decode ["a"; "not%20"; "b"] = "/a/not%2520/b"
val decode : string -> (path, string) Stdlib.result

decode s decodes an absolute-path to its percent-decoded list of segments. By definition of absolute-path the list of segments is never empty.

Here are a few examples:

  • decode "/" = Some [""]
  • decode "//" = Some ["",""]
  • decode "/a/b/c" = Some ["a";"b";"c"]
  • decode "/a/b//c" = Some ["a";"b";"";"c"]
  • decode "/a/b/c/" = Some ["a";"b";"c";""]
  • decode "/a/b/c/%20" = Some ["a";"b";"c";" "]
  • decode "/a/b//c//" = Some ["a";"b";"";"c";"";""]
  • decode "/a/b%2F/c" = Some ["a"; "b/"; "c"]
  • decode "/r%C3%C9volte" = Some ["r\xC3\xC9volte"]
  • decode "/a/not%2520/b" = Some ["a"; "not%20"; "b"]
  • decode "" = Error _
  • decode "a/b/c" = Error _
val pp : Stdlib.Format.formatter -> path -> unit

pp is an unspecified formatter for paths.