Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/dream.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,13 @@ val router : route list -> handler
request's prefix to be extended by it. It is mainly useful for “mounting”
{!Dream.static} as a subsite.

Route paths are matched against the decoded request path. In route
literals, write decoded characters such as ["/photos/södermalm/"], not the
percent-encoded wire form such as ["/photos/s%C3%B6dermalm/"]. The original
target, returned by {!Dream.target} and printed by the logger, remains
percent-encoded so it can be recorded without interpreting arbitrary client
input.

It can also be used as an escape hatch to convert a handler, which may
include its own router, into a subsite. However, it is better to compose
sites with routes and {!Dream.scope} rather than opaque handlers and [**],
Expand Down
11 changes: 11 additions & 0 deletions test/expect/server/router.ml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,17 @@ let%expect_test _ =
Response: 200 OK
foo |}]

let%expect_test _ =
show "/photos/s%C3%B6dermalm_pride/" @@ Dream.router [
Dream.get "/photos/s%C3%B6dermalm_pride/" (fun _ ->
Dream.respond "encoded");
Dream.get "/photos/södermalm_pride/" (fun _ ->
Dream.respond "decoded");
];
[%expect {|
Response: 200 OK
decoded |}]

(* Router matches long paths, does not match prefixes, etc. *)

let%expect_test _ =
Expand Down
Loading