Skip to content

Use new maintained django-cors-headers package #10000

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
Feb 9, 2023
Merged

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Feb 7, 2023

May be blocked by adamchainz/django-cors-headers#830, but we could also just have a single regex for all the allowed URLs.

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

This looks good to me. I'd not block this PR on the setting config. I'd go ahead with the solution you proposed (url1|url2). This string can be generated looping over the current list we already have:

# Generate the regex string manually because a list is not supported
# https://github.com/adamchainz/django-cors-headers/issues/830
CORS_URLS_REGEX = "(" + "|".join(CORS_URLS_ALLOW_ALL_REGEX) + ")"

Example,

>>> l = ['1', '2', '3', '4']
>>> '(' + '|'.join(l) + ')'
'(1|2|3|4)'
>>>

@stsewd
Copy link
Member Author

stsewd commented Feb 8, 2023

They aren't going to add that option, so back to use a long regex instead. I also hit adamchainz/django-cors-headers#558, but it was more of an issue with our tests, we were trying to test that middleware isolated passing a dictionary as the response, instead of creating a response, I'm just testing the whole request instead.

@stsewd stsewd marked this pull request as ready for review February 8, 2023 23:32
@stsewd stsewd requested a review from a team as a code owner February 8, 2023 23:32
@stsewd stsewd requested a review from humitos February 8, 2023 23:32
Comment on lines +747 to +749
CORS_ALLOW_HEADERS = list(default_headers) + [
'x-hoverxref-version',
'x-csrftoken'
)
]
Copy link
Member

Choose a reason for hiding this comment

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

Just to note we are adding 3 extra allowed headers with this change:

    "accept-encoding",
    "dnt",
    "user-agent",

r"^/api/v3/embed",
r"^/api/v2/sustainability",
]
CORS_URLS_REGEX = re.compile(
Copy link
Member

Choose a reason for hiding this comment

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

In the docs it says this is a string. However, it also says Pattern[str] which I'm not sure if that's what re.compile returns or not: https://github.com/adamchainz/django-cors-headers#cors_urls_regex-str--patternstr

Copy link
Member Author

Choose a reason for hiding this comment

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

@stsewd stsewd merged commit ff3b2a7 into main Feb 9, 2023
@stsewd stsewd deleted the use-django-cors-headers branch February 9, 2023 23:16
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.

2 participants