sanic: strict_slashes is not respected from the application level
Describe the bug
This issue is porting from huge-success/sanic-openapi#102. When using Sanic(strict_slashes=True), it won’t be apply to any blueprint.
Code snippet
from sanic import Sanic, Blueprint
from sanic.response import text
app = Sanic(strict_slashes=True)
bp = Blueprint("bp")
@bp.get("/test")
async def test(request):
return text("test")
app.blueprint(bp)
for route in app.router.routes_all:
print(route)
Output:
/test
/test/
Expected behavior
The strict_slashes in app level should be respected until user override it by setting Blueprint(..., strict_slashes=True) or in blueprint’s route level.
Environment (please complete the following information):
- OS: Ubuntu 18.04
- Version: master(https://github.com/huge-success/sanic/commit/e36f398aa689cb1852a171f9e6e60f78d8fa21d5)
Additional context None
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 16 (16 by maintainers)
@chenjr0719 @ahopkins Agreed. I am changing the original PR to only include the changes required for addressing the
strict_slashesoption inheritance against the defined hierarchy.As for the change of default behavior implemented currently, let me move that discussion to the thread in community and see what comes out of it.
I’m working on a new router idea that would, among other things, address this. So unless anyone else wants to address this separately, I’ll have a fix for this in my proposed router.
@harshanarayana
Totally agree both.
I don’t think this is
strict_slashessupposed to do. At current implementation, It depends on theuriof the route.When the
strict_slashes=False, no matter youruriends with slash or not, it will create two endpoints, one with slash, another one without slash.When the
strict_slashes=Trueand theuriends without slash, there will be only one endpoint/testbe created.In the other hand, when the
uriends with slash, it will be opposite to the above case.I like your idea about when
strict_slashes=Trueallurishould ends with slash. It can simplify most cases. But, it also changes the behavior ofstrict_slashestotally. I’m afraid it will cause a big impact to users.I suggest to separate current discussion to two parts, one is about the override mechanism, another is how
strict_slashesworks.route->blueprint->application.strict_slashesworks, I have to say that we need more time and feedback to determine should we change it’s behavior or not. And I think this might also related to #1420.@ahopkins Works for me. However, I just opened a new PR with WIP tag to address this + the other dependency issue. Take a look when you can and let me know your feedback. It’s pending few documentation changes
@chenjr0719
@chenjr0719 😉 Was just joking. When I am done with the POC for it (probably not till next week at the earliest), I will definitely be looking for as much feedback and thoughts as possible since it will potentially be a big change (I am trying to make sure there will not be any API changes though).
Cool, expecting your awesome work.