-
Notifications
You must be signed in to change notification settings - Fork 27
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
Regex support added for ignore URL list in settings.py #116
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||
import logging | ||||||
import re | ||||||
import uuid | ||||||
from typing import TYPE_CHECKING, Optional, Union | ||||||
|
||||||
|
@@ -91,3 +92,20 @@ def validate_guid(original_guid: str) -> bool: | |||||
return bool(uuid.UUID(original_guid, version=4).hex) | ||||||
except ValueError: | ||||||
return False | ||||||
|
||||||
|
||||||
def ignored_regex_url(request: Union['HttpRequest', 'HttpResponse']) -> bool: | ||||||
""" | ||||||
Support for Regex added | ||||||
Checks if the current URL is defined in the `IGNORE_REGEX_URLS` setting. | ||||||
|
||||||
:return: Boolean | ||||||
""" | ||||||
endpoint = request.path.strip('/') | ||||||
|
||||||
IGNORE_URLS = [] | ||||||
for url in settings.ignore_regex_urls: | ||||||
url_regex = url.replace('*', r'[\s\S]*') # noqa | ||||||
url_regex = '^' + url_regex + '$' | ||||||
IGNORE_URLS.append(re.compile(url_regex)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will compile every regex twice every requests. It seems like a waste of processing power, and we will not get the benefits of compiled regex since they will bê compiled every time they are needed. I wonder if it is possible to compile tem just once, maybe in the middleware setup or at the |
||||||
return any(url.match(endpoint) for url in IGNORE_URLS) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make this a new setting, e.g.
ignore_url_regex
, we can also skip this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JonasKs Thanks for the suggestions. I have moved it to a new settings. But facing errors in CI pipeline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m on vacation, but I’ll check when I’m back. 😊