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(cors): disallow cors_enable & additional CORSMiddleware combo #2201

Merged
merged 3 commits into from
Dec 19, 2023

Conversation

vytas7
Copy link
Member

@vytas7 vytas7 commented Dec 16, 2023

Closes #1977.

@@ -461,10 +462,28 @@ def add_middleware(self, middleware: object) -> None:
# the chance that middleware may be None.
if middleware:
try:
self._unprepared_middleware += middleware
middleware = list(middleware) # type: ignore
Copy link
Member Author

Choose a reason for hiding this comment

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

Bonus points if anyone knows how type this correctly. Since we optionally allow passing in any object, mypy complains:

No overload variant of "list" matches argument type "object"  [call-overload]

Copy link
Member

Choose a reason for hiding this comment

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

I don't think you can. Maybe you can use

try:
  if TYPE_CHECKING:
    assert isinstance(middleware, Iterable)
  ...

But I'm not sure it's worth it

Copy link

codecov bot commented Dec 16, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0aac950) 100.00% compared to head (a9daa57) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2201   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           62        62           
  Lines         6876      6880    +4     
  Branches      1098      1099    +1     
=========================================
+ Hits          6876      6880    +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@CaselIT CaselIT left a comment

Choose a reason for hiding this comment

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

left a could of suggestions, but it looks ok also without applying them

@@ -461,10 +462,28 @@ def add_middleware(self, middleware: object) -> None:
# the chance that middleware may be None.
if middleware:
try:
self._unprepared_middleware += middleware
middleware = list(middleware) # type: ignore
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you can. Maybe you can use

try:
  if TYPE_CHECKING:
    assert isinstance(middleware, Iterable)
  ...

But I'm not sure it's worth it

falcon/app.py Show resolved Hide resolved
@vytas7 vytas7 merged commit 5b6e4c4 into falconry:master Dec 19, 2023
37 checks passed
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.

Better handling of cors_enable=True + added CORSMiddleware
2 participants