Skip to content

Cleanup builtin middlewares #778

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

Merged
merged 2 commits into from
Nov 10, 2022

Conversation

jtraub
Copy link
Contributor

@jtraub jtraub commented Nov 9, 2022

PR Checklist

  • Have you followed the guidelines in CONTRIBUTING.md?
  • Have you got 100% test coverage on new code?
  • Have you updated the prose documentation?
  • Have you updated the reference documentation?

Here I add exclude_opt_key to all middlewares (logging, rate_limiting) and do some code cleanup by reusing code either from utils or AbstractMiddleware where applicable, fixing typos in docstrings and unifying parameter typing.

I need to write a few tests (while we have tests for exclusion for AbstractMiddleware we need to make sure that params from config are properly wired to init args and we need at least one test per middleware for that) and update docs that all builtin middleware support exclusion via pattern list or opt key

Also, there is another question that needs to be discussed I think.

At the moment AbstractAuthenticationMiddleware uses exclude_from_auth_key param with the default value of exclude_from_auth. CSRFMiddleware uses exclude_from_csrf_key config property (default value is exclude_from_csrf) and session middleware has exclude_opt_key config prop with the default value of skip_session. All other middleware use exclude_opt_key param with None as its default value.

While having default value is ok for a middleware that users want to disable often (I think turning off CSRF or Auth happens more frequently than disabling logging on some handlers) but I think it would be great to be consistent with param name. So what do you think about deprecation and switching in the future to the same param name?

Sorry, something went wrong.

Copy link
Contributor

@Goldziher Goldziher left a comment

Choose a reason for hiding this comment

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

gr8

@jtraub jtraub force-pushed the cleanup_builtin_middleware branch from 5b43cc7 to 6e70b41 Compare November 10, 2022 08:20
@jtraub jtraub marked this pull request as ready for review November 10, 2022 08:34
Copy link
Contributor

@Goldziher Goldziher left a comment

Choose a reason for hiding this comment

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

Love it

@Goldziher Goldziher merged commit 2d539bb into litestar-org:main Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants