Skip to content

Commit

Permalink
Fix issue aws#129
Browse files Browse the repository at this point in the history
  • Loading branch information
hadrien committed Sep 30, 2016
1 parent 8199a76 commit a610962
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
8 changes: 5 additions & 3 deletions chalice/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ def __init__(self, query_params, headers, uri_params, method, body,
#: The parsed JSON from the body. This value should
#: only be set if the Content-Type header is application/json,
#: which is the default content type value in chalice.
if self.headers.get('Content-Type') == 'application/json':
# We'll need to address case insensitive header lookups
# eventually.
has_application_json_header = (
self.headers.get('Content-Type') == 'application/json'
or self.headers.get('content-type') == 'application/json'
)
if has_application_json_header:
self.json_body = body
else:
self.json_body = None
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,22 @@ def index():
assert raw_body == '{"foo": "bar"}'


def test_json_body_available_with_lowercase_content_type_key():
demo = app.Chalice('demo-app')

@demo.route('/', methods=['POST'])
def index():
return (demo.current_request.json_body, demo.current_request.raw_body)

event = create_event_with_body({'foo': 'bar'})
del event['params']['header']['Content-Type']
event['params']['header']['content-type'] = 'application/json'

json_body, raw_body = demo(event, context=None)
assert json_body == {'foo': 'bar'}
assert raw_body == '{"foo": "bar"}'


def test_content_types_must_be_lists():
demo = app.Chalice('app-name')

Expand Down

0 comments on commit a610962

Please sign in to comment.