Skip to content

Commit d723433

Browse files
authoredNov 5, 2024··
feat: REVPROXY settings dict (#192)
1 parent feb7849 commit d723433

File tree

7 files changed

+39
-14
lines changed

7 files changed

+39
-14
lines changed
 

‎CHANGELOG.rst

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
0.13.0 (Unreleased)
1+
0.13.0 (2024-11-05)
22
===================
33

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

69

710
0.12.0 (2023-10-19)

‎docs/settings.rst

+21-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
Settings
2-
==================
2+
========
33

4-
`REVPROXY_QUOTE_SPACES_AS_PLUS`: Tells revproxy if it spaces should be replaced by `+` or `%20`.
4+
Our configurations are all namespaced under the ``REVPROXY`` settings.
5+
6+
For example:
7+
8+
.. code-block:: python
9+
10+
REVPROXY = {
11+
'QUOTE_SPACES_AS_PLUS': True,
12+
}
13+
14+
15+
List of available settings
16+
--------------------------
17+
18+
QUOTE_SPACES_AS_PLUS
19+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
20+
21+
Default: ``True``
22+
23+
Indicates whether spaces should be replaced by %20 or + when parsing a URL.

‎revproxy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '0.12.0'
1+
__version__ = '0.13.0'
22

33
default_app_config = 'revproxy.apps.RevProxyConfig'

‎revproxy/apps.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ class RevProxyConfig(AppConfig):
1010

1111
def ready(self):
1212
super().ready()
13-
for setting, default_value in REVPROXY_DEFAULT_SETTINGS.items():
14-
setattr(
15-
settings,
16-
setting,
17-
getattr(settings, setting, default_value),
18-
)
13+
default_settings = {
14+
'REVPROXY': REVPROXY_DEFAULT_SETTINGS
15+
}
16+
17+
if not hasattr(settings, 'REVPROXY'):
18+
setattr(settings, 'REVPROXY', default_settings['REVPROXY'])
19+
else:
20+
for key, value in default_settings['REVPROXY'].items():
21+
settings.REVPROXY.setdefault(key, value)

‎revproxy/settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
REVPROXY_DEFAULT_SETTINGS = {
2-
'REVPROXY_QUOTE_SPACES_AS_PLUS': True,
2+
'QUOTE_SPACES_AS_PLUS': True,
33
}

‎revproxy/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def get_request_headers(self):
169169

170170
def get_quoted_path(self, path):
171171
"""Return quoted path to be used in proxied request"""
172-
if settings.REVPROXY_QUOTE_SPACES_AS_PLUS:
172+
if settings.REVPROXY["QUOTE_SPACES_AS_PLUS"]:
173173
return quote_plus(path.encode('utf8'), QUOTE_SAFE)
174174
else:
175175
return quote(path.encode('utf8'), QUOTE_SAFE)

‎tests/test_views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class CustomProxyView(ProxyView):
212212
decode_content=False,
213213
headers=headers)
214214

215-
@override_settings(REVPROXY_QUOTE_SPACES_AS_PLUS=False)
215+
@override_settings(REVPROXY={'QUOTE_SPACES_AS_PLUS': False})
216216
def test_space_is_escaped_disabled(self):
217217
class CustomProxyView(ProxyView):
218218
upstream = 'http://example.com'

0 commit comments

Comments
 (0)
Please sign in to comment.