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

Allow for a more flexible/customisable injection time throughout a request's lifetime #19

Closed
prryplatypus opened this issue Dec 9, 2021 · 1 comment · Fixed by #127
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@prryplatypus
Copy link
Member

Is your feature request related to a problem? Please describe your use case.
Currently when a parameter is defined for injection, the injection happens before anything else. This makes it hard for usecases such as ratelimiting or authentication middlewares, as these are executed after the injection. In cases where handlers should be ratelimited to reduce load (on a database, for example) this makes ratelimiting useless, as the database is always hit before the user has a chance to stop the request. Another usecase would be checking for a valid authentication before injecting any parameters.

Describe the solution you'd like
A few possibilities considered:

  • Ability to determine signal at which parameters are injected (new signals?)
  • Add a configuration value to determine whether injection should happen automatically or not (+@no_auto_inject and @inject decorators to determine where injection should occur)
  • Some other solution that you (the reader) can come up with? 🙃

Additional context
N/A

@ahopkins
Copy link
Member

I think option 1 makes the most sense. We would need to add a new signal to the core handle_request, but that should be doable. Then the API for this would be something like this:

def add_injection(
    app: Sanic,
    injection_registry: InjectionRegistry,
    signal: Event.HTTP_ROUTING_AFTER,  # << This being a new argument
) -> None:
    ...

add_injection(..., Event.HTTP_LIFECYCLE_RUN_HANDLER)  # or some better named event

@ahopkins ahopkins added help wanted Extra attention is needed good first issue Good for newcomers labels Mar 24, 2022
@prryplatypus prryplatypus linked a pull request Sep 11, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants