Skip to content
Snippets Groups Projects
Commit 3b31fec1 authored by Bruce Flynn's avatar Bruce Flynn
Browse files

initial

parents
Branches
Tags
No related merge requests found
.idea
.cache
.eggs
.coverage
*.egg-info
dist
build
setup.py 0 → 100644
from setuptools import setup
setup(
name='wsgiware',
py_modules=['wsgiware'],
use_scm_version=True,
setup_requires=['setuptools_scm'],
entry_points="""
[paste.filter_factory]
add_headers = wsgiware.add_headers:factory
""",
)
import copy
def factory(global_conf, **settings):
"""
Factory for use by PasteDeploy INI configuration. To use::
# wrap our API app with the headers app configured below
[pipeline:main]
pipeline =
headers
app
# Add the following headers to all requests
[filter:headers]
use = egg:sipswebapi#headers
My-Header = MY_HEADER_VALUE
:param global_conf: Global INI config
:param settings: Settings from INI config section
:return: Factory that takes an app
"""
headers = settings
def factory(app):
return AddHeadersMiddleware(app, headers)
return factory
class AddHeadersMiddleware(object):
def __init__(self, app, headers):
self.app = app
self.headers = copy.deepcopy(headers)
def __call__(self, environ, start_response):
def x_start_response(status, headers, exc_info=None):
for name, val in self.headers.items():
headers.append((name, val))
return start_response(status, headers, exc_info)
return self.app(environ, x_start_response)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment