Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add case-insensitive routing #2354

Merged
merged 4 commits into from Jun 24, 2020
Merged

Conversation

tdotclare
Copy link
Contributor

@tdotclare tdotclare commented May 12, 2020

Allows configuring case-insensitive routing (#2354).

// Enables case-insensitive routing.
// Defaults to false.
app.routes.caseInsensitive = true

…outes (defaults to false)

* DefaultResponder will configure TrieRouter appropriately if set to true
* Appropriate test
@tdotclare
Copy link
Contributor Author

Someone asked yesterday on Discord about case insensitive routing. I don't know that I'd ever actually ADVISE someone to do this, but since TrieRouter can do it, this PR adds a configurable setting to app.routes so DefaultResponder can grab it and pass it to TrieRouter.

Whether this is a Good Idea is up for debate and feel free to skip approving it if not, hah

@0xTim
Copy link
Member

0xTim commented May 18, 2020

I'm +1 for at least exposing this

Copy link
Member

@tanner0101 tanner0101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to adding this, thanks! Would you mind add a note to https://github.com/vapor/docs/blob/master/4.0/docs/routing.md as well?

Sources/Vapor/Routing/Routes.swift Show resolved Hide resolved
@tanner0101 tanner0101 added the enhancement New feature or request label May 28, 2020
@tanner0101 tanner0101 added this to Awaiting Review in Vapor 4 via automation May 28, 2020
@tanner0101 tanner0101 moved this from Awaiting Review to Awaiting Updates in Vapor 4 May 28, 2020
@tanner0101 tanner0101 added the semver-minor Contains new API label May 28, 2020
@tanner0101
Copy link
Member

Please format the PR title / body as release notes, too.

@tdotclare
Copy link
Contributor Author

Initial PR comments reproduced:

  • Adds Application.Routes.caseInsensitive flag to allow configuring case insensitive routes prior to boot (defaults to false)
  • DefaultResponder will configure TrieRouter appropriately if set to true
  • Appropriate test

Allows configuring Vapor to use case insensitive route handling

EG:

app.routes.caseInsensitive = true
app.routes.get("foo") {...}
app.run()
...
myserver.com/foo -> "200 OK"
myserver.com/FOO -> "200 OK"

Note that case-insensitive routing is somewhat less performant, and only applies to constant PathComponents - eg: app.routes.get("foo", ":id") maintains case of URL request to parameter id, so myserver.com/FoO/uSeRiD would correctly hit the registered route handler but within the route handler, the value of id will still be uSeRiD.

@tdotclare tdotclare changed the title Case Insensitive Routing Add Case Insensitive Routing Configuration May 28, 2020
@tdotclare tdotclare changed the title Add Case Insensitive Routing Configuration Add Case Insensitive Routing May 28, 2020
@tanner0101 tanner0101 changed the title Add Case Insensitive Routing Add case-insensitive routing Jun 24, 2020
@tanner0101 tanner0101 merged commit 9d57bde into vapor:master Jun 24, 2020
Vapor 4 automation moved this from Awaiting Updates to Done Jun 24, 2020
@tanner0101
Copy link
Member

These changes are now available in 4.12.0

@tdotclare tdotclare deleted the router-caseinsensitive branch June 25, 2020 16:19
@maclee99
Copy link

maclee99 commented Jul 1, 2020

missing an "I" in the app.routes.caseInsenstive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request semver-minor Contains new API
Projects
Vapor 4
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants