diff options
author | Loïc Hoguin <[email protected]> | 2020-05-20 10:53:52 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2020-05-20 10:53:52 +0200 |
commit | 78b23ddfa555136ddf9cd81396e5375845de219c (patch) | |
tree | 442ee61f6aa6fcd7805d81af13004111098d2bd4 /doc/src/guide/routing.asciidoc | |
parent | 0d0e7d164c72799b48275c0c79a7a9d5c08e652e (diff) | |
download | cowboy-78b23ddfa555136ddf9cd81396e5375845de219c.tar.gz cowboy-78b23ddfa555136ddf9cd81396e5375845de219c.tar.bz2 cowboy-78b23ddfa555136ddf9cd81396e5375845de219c.zip |
Clarify the routing algorithm
Diffstat (limited to 'doc/src/guide/routing.asciidoc')
-rw-r--r-- | doc/src/guide/routing.asciidoc | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/doc/src/guide/routing.asciidoc b/doc/src/guide/routing.asciidoc index 9e2ef25..37d3e5a 100644 --- a/doc/src/guide/routing.asciidoc +++ b/doc/src/guide/routing.asciidoc @@ -6,9 +6,26 @@ Cowboy does nothing by default. To make Cowboy useful, you need to map URIs to Erlang modules that will handle the requests. This is called routing. -When Cowboy receives a request, it tries to match the requested host and -path to the configured routes. When there's a match, the route's -associated handler is executed. +Cowboy routes requests using the following algorithm: + +* If no configured host matches the request URI, a 400 response + is returned. + +* Otherwise, the first configured host that matches the request + URI will be used. Only the paths configured for this host will + be considered. + +* If none of the configured paths found in the previous step + match the request URI, a 404 response is returned. + +* Otherwise, the handler and its initial state are added to the + environment and the request continues to be processed. + +NOTE: It is possible to run into a situation where two hosts match a +request URI, but only the paths on the second host match the +request URI. In this case the expected result is a 404 response +because the only paths used during routing are the paths from +the first configured host that matches the request URI. Routes need to be compiled before they can be used by Cowboy. The result of the compilation is the dispatch rules. |