package cohttp

  1. Overview
  2. Docs

Source file path.ml

1
2
3
4
5
6
7
8
9
10
11
12
let remove_dot_segments path =
  let rec go acc = function
    | [] -> List.rev acc
    | ("" | ".") :: rest -> go acc rest
    | ".." :: rest -> (
        match acc with [] -> go [] rest | _ :: tl -> go tl rest)
    | seg :: rest -> go (seg :: acc) rest
  in
  path |> String.split_on_char '/' |> go [] |> String.concat "/"

let normalise uri = uri |> Uri.path |> Uri.pct_decode |> remove_dot_segments
let resolve_local_file ~docroot ~uri = Filename.concat docroot (normalise uri)