Skip to content

Commit

Permalink
CLI. Added headers related methods to routing options group.
Browse files Browse the repository at this point in the history
  • Loading branch information
idlesign committed Oct 31, 2017
1 parent 162e7f5 commit 4192e9a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ uwsgiconf changelog

Unreleased
----------
+ CLI. Added headers related methods to routing options group.
+ Added 'master_process.set_exception_handling_params'.
* 'Logging.set_filters' split into 'set_filters' and 'set_requests_filters'.
* Signal.register_handler target now defaults to 'worker'.
Expand Down
16 changes: 16 additions & 0 deletions tests/options/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ def test_routing_basics(assert_lines):
'plugin = geoip\ngeoip-city = GeoLiteCity.dat',
], Section().routing.set_geoip_params(db_city='GeoLiteCity.dat'))

assert_lines([
'del-header = Connection',
], Section().routing.header_remove('Connection'))

assert_lines([
'add-header = Connection: Keep-Alive',
], Section().routing.header_add('Connection', 'Keep-Alive'))

assert_lines([
'pull-header = X-Offload-to-SSE X_OFFLOAD',
], Section().routing.header_collect('X-Offload-to-SSE', 'X_OFFLOAD', pull=True))

assert_lines([
'collect-header = Content-Type CONTENT_TYPE',
], Section().routing.header_collect('Content-Type', 'CONTENT_TYPE'))


def test_routing_rules(assert_lines):
rule = Section.routing.route_rule
Expand Down
39 changes: 39 additions & 0 deletions uwsgiconf/options/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,42 @@ def set_geoip_params(self, db_country=None, db_city=None):
self._set('geoip-city', db_city, plugin='geoip')

return self._section

def header_add(self, name, value):
"""Automatically add HTTP headers to response.
:param str|unicode name:
:param str|unicode value:
"""
self._set('add-header', '%s: %s' % (name, value), multi=True)

return self._section

def header_remove(self, value):
"""Automatically remove specified HTTP header from the response.
:param str|unicode value:
"""
self._set('del-header', value, multi=True)

return self._section

def header_collect(self, name, target_var, pull=False):
"""Store the specified response header in a request var
(optionally removing it from the response).
:param str|unicode name:
:param str|unicode target_var:
:param bool pull: Whether to remove header from response.
"""
self._set(
'pull-header' if pull else 'collect-header',
'%s %s' % (name, target_var), multi=True)

return self._section

0 comments on commit 4192e9a

Please sign in to comment.