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

feat(rest): add route paths case sensitive option #4401

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cyntler
Copy link

@cyntler cyntler commented Sep 29, 2024

This pull request adds an option to switch between supporting case sensitive and insensitive router paths.
The options can be set in the YAML configuration file. Defaults to true.

config.yml

Name: HelloWorld
Host: 127.0.0.1
Port: 8080
RoutePathsCaseSensitive: true

After change RoutePathsCaseSensitive to false, /hELLo/wORLD request path should work for below example:

s.AddRoute(rest.Route{
    Method: http.MethodGet,
    Path:   "/hello/world",
    Handler: func(writer http.ResponseWriter, request *http.Request) {
        httpx.OkJson(writer, "Hello World!")
    },
})

Closes #4392

@kevwan
Copy link
Contributor

kevwan commented Oct 2, 2024

https://www.w3.org/TR/WD-html40-970708/htmlweb.html

URLs in general are case-sensitive (with the exception of machine names). There may be URLs, or parts of URLs, where case doesn't matter, but identifying these may not be easy. Users should always consider that URLs are case-sensitive.

@kevwan kevwan added the do-not-merge/hold Indicates that a PR should not merge because of known issues or need more discussion. label Oct 2, 2024
@cyntler
Copy link
Author

cyntler commented Oct 7, 2024

https://www.w3.org/TR/WD-html40-970708/htmlweb.html

URLs in general are case-sensitive (with the exception of machine names). There may be URLs, or parts of URLs, where case doesn't matter, but identifying these may not be easy. Users should always consider that URLs are case-sensitive.

OK, I see. Generally you are right, although I don't know if this is a problematic option. For example, the popular Express.js for Node.js supports case sensitive defined at the Router level: https://expressjs.com/en/5x/api.html#express.router. I thought this could be a useful option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold Indicates that a PR should not merge because of known issues or need more discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

go-zero doesn't support case-insensitive route
2 participants