Skip to content

Commit

Permalink
Fix int conversion errors when CONTENT_LENGTH is ''
Browse files Browse the repository at this point in the history
Earlier versions of Werkzerg created a default of ''
for the CONTENT_LENGTH environ var if the client
did not provide the header.

See pallets/werkzeug#1056
  • Loading branch information
markstuart committed Apr 7, 2020
1 parent 9a8bf57 commit 2d0e4fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 9 additions & 7 deletions python2/raygun4py/http_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand All @@ -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_'):
Expand Down
16 changes: 9 additions & 7 deletions python3/raygun4py/http_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand All @@ -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_'):
Expand Down

0 comments on commit 2d0e4fd

Please sign in to comment.