diff --git a/python2/raygun4py/http_utilities.py b/python2/raygun4py/http_utilities.py index bd29a4a..9e5f8ad 100644 --- a/python2/raygun4py/http_utilities.py +++ b/python2/raygun4py/http_utilities.py @@ -22,9 +22,9 @@ def build_wsgi_compliant_request(request): # fallback to wsgi.input if http_form is None and 'wsgi.input' in request: # we can assume WSGI keys inside this block - content_length = int(request.get('CONTENT_LENGTH', 0)) - if content_length: - http_form = request['wsgi.input'].read(content_length) + content_length = request.get('CONTENT_LENGTH', 0) + if content_length and content_length != '': + http_form = request['wsgi.input'].read(int(content_length)) rg_request = { 'httpMethod': (request.get('httpMethod') or request.get('REQUEST_METHOD')), @@ -43,10 +43,12 @@ def build_wsgi_compliant_request(request): _headers = request.get('headers') if _headers is None: # manually try to build up headers given known WSGI keys - _headers = { - 'Content-Type': request.get('CONTENT_TYPE'), - 'Content-Length': request.get('CONTENT_LENGTH'), - } + _headers = {} + # don't add content headers if they are empty strings, Werkzeug has strange defaults + if request.get('CONTENT_TYPE') != '': + _headers['Content-Type'] = request.get('CONTENT_TYPE') + if request.get('CONTENT_LENGTH') != '': + _headers['Content-Length'] = request.get('CONTENT_LENGTH') for key, value in request.items(): if key.startswith('HTTP_'): diff --git a/python2/raygun4py/middleware/flask.py b/python2/raygun4py/middleware/flask.py index 36f19fb..676278e 100644 --- a/python2/raygun4py/middleware/flask.py +++ b/python2/raygun4py/middleware/flask.py @@ -11,9 +11,10 @@ class Provider(object): - def __init__(self, flaskApp, apiKey): + def __init__(self, flaskApp, apiKey, config=None): self.flaskApp = flaskApp self.apiKey = apiKey + self.config = config self.sender = None got_request_exception.connect(self.send_exception, sender=flaskApp) @@ -24,7 +25,7 @@ def attach(self): if not hasattr(self.flaskApp, 'extensions'): self.flaskApp.extensions = {} - self.sender = raygunprovider.RaygunSender(self.apiKey) + self.sender = raygunprovider.RaygunSender(self.apiKey, config=self.config) return self.sender def send_exception(self, *args, **kwargs): diff --git a/python2/raygun4py/middleware/wsgi.py b/python2/raygun4py/middleware/wsgi.py index 6fd201d..61ddee7 100644 --- a/python2/raygun4py/middleware/wsgi.py +++ b/python2/raygun4py/middleware/wsgi.py @@ -8,9 +8,9 @@ class Provider(object): - def __init__(self, app, apiKey): + def __init__(self, app, apiKey, config=None): self.app = app - self.sender = raygunprovider.RaygunSender(apiKey) + self.sender = raygunprovider.RaygunSender(apiKey, config=config) def __call__(self, environ, start_response): if not self.sender: diff --git a/python3/raygun4py/http_utilities.py b/python3/raygun4py/http_utilities.py index bd29a4a..9e5f8ad 100644 --- a/python3/raygun4py/http_utilities.py +++ b/python3/raygun4py/http_utilities.py @@ -22,9 +22,9 @@ def build_wsgi_compliant_request(request): # fallback to wsgi.input if http_form is None and 'wsgi.input' in request: # we can assume WSGI keys inside this block - content_length = int(request.get('CONTENT_LENGTH', 0)) - if content_length: - http_form = request['wsgi.input'].read(content_length) + content_length = request.get('CONTENT_LENGTH', 0) + if content_length and content_length != '': + http_form = request['wsgi.input'].read(int(content_length)) rg_request = { 'httpMethod': (request.get('httpMethod') or request.get('REQUEST_METHOD')), @@ -43,10 +43,12 @@ def build_wsgi_compliant_request(request): _headers = request.get('headers') if _headers is None: # manually try to build up headers given known WSGI keys - _headers = { - 'Content-Type': request.get('CONTENT_TYPE'), - 'Content-Length': request.get('CONTENT_LENGTH'), - } + _headers = {} + # don't add content headers if they are empty strings, Werkzeug has strange defaults + if request.get('CONTENT_TYPE') != '': + _headers['Content-Type'] = request.get('CONTENT_TYPE') + if request.get('CONTENT_LENGTH') != '': + _headers['Content-Length'] = request.get('CONTENT_LENGTH') for key, value in request.items(): if key.startswith('HTTP_'): diff --git a/python3/raygun4py/middleware/flask.py b/python3/raygun4py/middleware/flask.py index 11fdae4..f859829 100644 --- a/python3/raygun4py/middleware/flask.py +++ b/python3/raygun4py/middleware/flask.py @@ -7,9 +7,10 @@ class Provider(object): - def __init__(self, flaskApp, apiKey): + def __init__(self, flaskApp, apiKey, config=None): self.flaskApp = flaskApp self.apiKey = apiKey + self.config = config self.sender = None got_request_exception.connect(self.send_exception, sender=flaskApp) @@ -20,7 +21,7 @@ def attach(self): if not hasattr(self.flaskApp, 'extensions'): self.flaskApp.extensions = {} - self.sender = raygunprovider.RaygunSender(self.apiKey) + self.sender = raygunprovider.RaygunSender(self.apiKey, config=self.config) return self.sender def send_exception(self, *args, **kwargs): diff --git a/python3/raygun4py/middleware/wsgi.py b/python3/raygun4py/middleware/wsgi.py index 6fd201d..61ddee7 100644 --- a/python3/raygun4py/middleware/wsgi.py +++ b/python3/raygun4py/middleware/wsgi.py @@ -8,9 +8,9 @@ class Provider(object): - def __init__(self, app, apiKey): + def __init__(self, app, apiKey, config=None): self.app = app - self.sender = raygunprovider.RaygunSender(apiKey) + self.sender = raygunprovider.RaygunSender(apiKey, config=config) def __call__(self, environ, start_response): if not self.sender: