Skip to content

Commit

Permalink
feat: REVPROXY settings dict (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
andruten authored Nov 5, 2024
1 parent feb7849 commit d723433
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 14 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
0.13.0 (Unreleased)
0.13.0 (2024-11-05)
===================

* Added new `REVPROXY_QUOTE_SPACES_AS_PLUS` setting
* Added `REVPROXY` settings dict #192
* Let encode spaces as `%20` or `+` #191
* Cast int cookie dict max_age #185
* Replaced deprecated getheader in favor of headers #184


0.12.0 (2023-10-19)
Expand Down
23 changes: 21 additions & 2 deletions docs/settings.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
Settings
==================
========

`REVPROXY_QUOTE_SPACES_AS_PLUS`: Tells revproxy if it spaces should be replaced by `+` or `%20`.
Our configurations are all namespaced under the ``REVPROXY`` settings.

For example:

.. code-block:: python
REVPROXY = {
'QUOTE_SPACES_AS_PLUS': True,
}
List of available settings
--------------------------

QUOTE_SPACES_AS_PLUS
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Default: ``True``

Indicates whether spaces should be replaced by %20 or + when parsing a URL.
2 changes: 1 addition & 1 deletion revproxy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '0.12.0'
__version__ = '0.13.0'

default_app_config = 'revproxy.apps.RevProxyConfig'
15 changes: 9 additions & 6 deletions revproxy/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ class RevProxyConfig(AppConfig):

def ready(self):
super().ready()
for setting, default_value in REVPROXY_DEFAULT_SETTINGS.items():
setattr(
settings,
setting,
getattr(settings, setting, default_value),
)
default_settings = {
'REVPROXY': REVPROXY_DEFAULT_SETTINGS
}

if not hasattr(settings, 'REVPROXY'):
setattr(settings, 'REVPROXY', default_settings['REVPROXY'])
else:
for key, value in default_settings['REVPROXY'].items():
settings.REVPROXY.setdefault(key, value)
2 changes: 1 addition & 1 deletion revproxy/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
REVPROXY_DEFAULT_SETTINGS = {
'REVPROXY_QUOTE_SPACES_AS_PLUS': True,
'QUOTE_SPACES_AS_PLUS': True,
}
2 changes: 1 addition & 1 deletion revproxy/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def get_request_headers(self):

def get_quoted_path(self, path):
"""Return quoted path to be used in proxied request"""
if settings.REVPROXY_QUOTE_SPACES_AS_PLUS:
if settings.REVPROXY["QUOTE_SPACES_AS_PLUS"]:
return quote_plus(path.encode('utf8'), QUOTE_SAFE)
else:
return quote(path.encode('utf8'), QUOTE_SAFE)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class CustomProxyView(ProxyView):
decode_content=False,
headers=headers)

@override_settings(REVPROXY_QUOTE_SPACES_AS_PLUS=False)
@override_settings(REVPROXY={'QUOTE_SPACES_AS_PLUS': False})
def test_space_is_escaped_disabled(self):
class CustomProxyView(ProxyView):
upstream = 'http://example.com'
Expand Down

0 comments on commit d723433

Please sign in to comment.