Skip to content

Let the application answer the root path / itself [#740] - #745

Open
ambroise-leclerc wants to merge 2 commits into
developfrom
740-root-route
Open

ambroise-leclerc wants to merge 2 commits into
developfrom
740-root-route

Conversation

@ambroise-leclerc

Copy link
Copy Markdown
Collaborator

Closes #740.

Based on #743 (#741): the root route's tests and the lobby example use http::redirectReply and Response::seeOther. Merge #743 first; this PR's own change is its last commit.

Changes

  • app.addRootRoute(handler[, options]) (and http::Server::addRootRoute, RouteTable::addRoot): a route that answers the path / alone, any query included, for GET and HEAD (and POST with postBodyLimit), before the file providers that would serve the document root's index.html. The forms the server reads as / (//, /./) are included, as they would have served index.html.
  • Every other path keeps its routing: /index.html, /other/, the prefix routes, the mounts. A prefix route still cannot be /.
  • Under a family of spaces, /s/<id>/ still serves index.html: the root route belongs to the application, so matchRoute skips it for a mounted request.
  • One root route at a time (std::invalid_argument), as for overlapping prefixes; secretPath is refused; the registration removes it.
  • Documented in docs/HTTP_ASSETS.md and docs/SPACES.md (new section "A session lobby"); changelog entry.

Tests

The root route answers / alone, and the root of a space keeps its index.html (#740): GET /, /?from=link, // and /./ reach the route (303 with Location); HEAD / too; POST / gets 405; /index.html and /other/ are served by the providers; /s/abc/ under a mount serves index.html; after reset() and without a root route / serves index.html; a second root route, an empty handler and a secret root are refused; prefix routes coexist.

CEF-off build and full CTest suite: 771/771 passed (the CUDA case skipped).

Response::StatusCode gains found, seeOther, temporaryRedirect and
permanentRedirect, written with their reason phrase. http::redirectReply(status,
location) builds a route reply with Location, an empty body and, for the
temporary ones, Cache-Control: no-store; it refuses a status that is not a
redirection and a location that is empty or holds a control character.
app.addRootRoute(handler) registers a route that answers the path / alone,
with any query, before the file providers that would serve the document
root's index.html. Every other path keeps its routing, and under a family of
spaces /s/<id>/ still serves index.html: the root route belongs to the
application, not to the spaces. A session lobby can thus redirect / to a new
session with a 303 in one step.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let the application answer the root path / itself (a session lobby redirecting with 303)

1 participant