This topic is an extension to the discussion started on issue #1420.
Related problem: when a route is created using strict_slashes=True
, this information is not available later to the url_for
function.
Real problem: the Router
object already have a lot of complexity and, with time, got intertwined with other objects, like Request
and HttpProtocol
, that may create some weird behavior on mutables (due to the lrucache
) and extra calls to Router.get
in a single Request
lifespan, that could be avoided by having an intermediate object (or Request
itself) to save the required data (further down the road). Also, another thing that can be worked within this issue is actually when to call the Router.get
function: not after having all the data available, but instead when at least all the headers
are available. This way, we can make some of the checks, like if a route
even exists for the given URL
and launch a 404 error and close the connection - to avoid situations like a 50mb body full of junk to be stored in memory and just then check if the route really exists. It doesn’t make much sense in terms of performance to act like that.
Rationale: see this post onwards.
Objects impacted: Router
, Sanic
, HttpProtocol
, Request
.
Related issues and PRs: #1317, #1373.
Thoughts?