package dream

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file site_prefix.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
(* This file is part of Dream, released under the MIT license. See
   LICENSE.md for details, or visit https://github.com/aantron/dream.

   Copyright 2021 Anton Bachin *)



module Dream = Dream__pure.Inmost



let rec match_site_prefix prefix path =
  match prefix, path with
  | prefix_crumb::prefix, path_crumb::path ->
    if path_crumb = prefix_crumb then
      match_site_prefix prefix path
    else
      None
  | [], path ->
    Some path
  | _ ->
    None



(* TODO The path and prefix representations and accessors need a cleanup. *)
let chop_site_prefix prefix =
  let prefix =
    prefix
    |> Dream__pure.Formats.from_target_path
    |> Dream__pure.Formats.drop_trailing_slash
  in

  let prefix_reversed = List.rev prefix in

  fun next_handler request ->
    match match_site_prefix prefix (Dream.path request) with
    | None ->
      Dream.empty `Bad_Gateway
    | Some path ->
      request
      |> Dream.with_prefix prefix_reversed
      |> Dream.with_path path
      |> next_handler
OCaml

Innovation. Community. Security.