View raw

1 (** URL paths, in both directions. 2 3 One {!t} value describes a page, and the same value both generates a link 4 ({!path_of}) and is recovered from an incoming request ({!dispatch}). For 5 every route [r], [dispatch] inverts [path_of]: 6 [dispatch (path_of r without its leading slash) = Some r]. Keeping the two 7 directions in one module is what stops generated links and served routes 8 from drifting apart. 9 10 Only path-shaped routes live here. Query parameters — the commit list's 11 filters and page number — are not modelled, because they refine a page 12 rather than identify one. 13 14 The segments [summary], [commits], [commit], [files], [file], and [raw] are 15 reserved: they mark where a repository path ends, so a repository or 16 directory carrying one of these names is not reachable. *) 17 18 (** {1 Routes} *) 19 20 type t = 21 | Root 22 | Project_dir of string 23 | Repo of string 24 | Commits of string 25 | Commits_branch of string * string 26 | Commit of string * string 27 | Files of string 28 | File of string * string 29 | File_at of string * string 30 | Raw_file of string * string 31 | Raw_at of string * string 32 (** A page in the application. The string arguments carry the repository 33 name and either an object identifier ({!File}, {!Raw_file}) or a 34 slash-separated file path from the repository root ({!File_at}, 35 {!Raw_at}). 36 37 Path arguments are percent-encoded by {!path_of} and decoded by 38 {!dispatch}, so file names survive the round trip unaltered. A 39 single-segment path that is itself 40 hexadecimal characters is 40 indistinguishable from an object id and dispatches as one. *) 41 42 val path_of : t -> string 43 (** Generate the URL path for a route. *) 44 45 (** {1 Dispatch} *) 46 47 val dispatch : string -> t option 48 (** Parse a request path (without leading slash) back into a route. Returns 49 [None] when the path matches no known route, including a recognised route 50 followed by extra segments. 51 52 A path without a reserved segment comes back as {!Project_dir} even when it 53 names a repository: only the filesystem can tell the two apart, so the 54 handler resolves which page to serve. *) 55