diff options
-rw-r--r-- | docs/news.txt | 4 | ||||
-rw-r--r-- | paste/proxy.py | 19 |
2 files changed, 19 insertions, 4 deletions
diff --git a/docs/news.txt b/docs/news.txt index b8d75fb..ff9571a 100644 --- a/docs/news.txt +++ b/docs/news.txt @@ -47,6 +47,10 @@ News ``paste.urlparser.StaticURLParser``, which allows you to encourage the caching of static files. Patch from Brad Clements. +* Added ``suppress_http_headers`` to ``paste.proxy.Proxy``, which will + filter out HTTP headers from the request before passing it on. + Patch from Brad Clements. + 0.9.7 ----- diff --git a/paste/proxy.py b/paste/proxy.py index aff824d..40b886e 100644 --- a/paste/proxy.py +++ b/paste/proxy.py @@ -42,7 +42,8 @@ filtered_headers = ( class Proxy(object): - def __init__(self, address, allowed_request_methods=()): + def __init__(self, address, allowed_request_methods=(), + suppress_http_headers=()): self.address = address self.parsed = urlparse.urlsplit(address) self.scheme = self.parsed[0].lower() @@ -51,6 +52,8 @@ class Proxy(object): self.allowed_request_methods = [ x.lower() for x in allowed_request_methods if x] + self.suppress_http_headers = [ + x.lower() for x in suppress_http_headers if x] def __call__(self, environ, start_response): if (self.allowed_request_methods and @@ -69,7 +72,7 @@ class Proxy(object): for key, value in environ.items(): if key.startswith('HTTP_'): key = key[5:].lower().replace('_', '-') - if key == 'host': + if key == 'host' or key in self.suppress_http_headers: continue headers[key] = value headers['host'] = self.host @@ -112,15 +115,22 @@ class Proxy(object): conn.close() return [body] -def make_proxy(global_conf, address, allowed_request_methods=""): +def make_proxy(global_conf, address, allowed_request_methods="", + suppress_http_headers=""): """ Make a WSGI application that proxies to another address -- 'address' should be the full URL ending with a trailing / 'allowed_request_methods' is a space seperated list of request methods + 'suppress_http_headers' is a space seperated list of http headers (lower case, without the leading http_) + that should not be passed on to target host """ from paste.deploy.converters import aslist allowed_request_methods = aslist(allowed_request_methods) - return Proxy(address, allowed_request_methods=allowed_request_methods) + suppress_http_headers = aslist(suppress_http_headers) + return Proxy( + address, + allowed_request_methods=allowed_request_methods, + suppress_http_headers=suppress_http_headers) class TransparentProxy(object): @@ -190,3 +200,4 @@ class TransparentProxy(object): body = res.read() conn.close() return [body] + |