Skip to content

Commit

Permalink
Default raw_body to empty bytestring
Browse files Browse the repository at this point in the history
Changed based on the PR feedback.
  • Loading branch information
jamesls committed Aug 31, 2017
1 parent 8f795f4 commit b237934
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions chalice/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def __init__(self, query_params, headers, uri_params, method, body,
#: only be set if the Content-Type header is application/json,
#: which is the default content type value in chalice.
self._json_body = None
self._raw_body = None
self._raw_body = b''
self.context = context
self.stage_vars = stage_vars

Expand All @@ -277,7 +277,7 @@ def _base64decode(self, encoded):

@property
def raw_body(self):
if self._raw_body is None and self._body is not None:
if not self._raw_body and self._body is not None:
if self._is_base64_encoded:
self._raw_body = self._base64decode(self._body)
elif not isinstance(self._body, bytes):
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def test_empty_raw_body(smoke_test_app):
url = smoke_test_app.url + '/repr-raw-body'
response = requests.post(url)
response.raise_for_status()
assert response.json() == {'repr-raw-body': 'None'}
assert response.json() == {'repr-raw-body': ''}


@pytest.mark.on_redeploy
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/testapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,4 @@ def fake_profile_post():

@app.route('/repr-raw-body', methods=['POST'])
def repr_raw_body():
return {'repr-raw-body': repr(app.current_request.raw_body)}
return {'repr-raw-body': app.current_request.raw_body.decode('utf-8')}
2 changes: 1 addition & 1 deletion tests/unit/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -1291,4 +1291,4 @@ def test_raw_body_is_none_if_body_is_none():
'is_base64_encoded': False,
}
request = app.Request(body=None, **misc_kwargs)
assert request.raw_body is None
assert request.raw_body == b''

0 comments on commit b237934

Please sign in to comment.