Skip to content

Commit

Permalink
Don't duplicate content type header in local mode
Browse files Browse the repository at this point in the history
Fixes aws#310
  • Loading branch information
jamesls committed Apr 28, 2017
1 parent 580b016 commit 173457d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions chalice/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def _send_http_response(self, lambda_event, response):
# type: (EventType, Dict[str, Any]) -> None
self.send_response(response['statusCode'])
self.send_header('Content-Length', str(len(response['body'])))
self.send_header(
'Content-Type',
response['headers'].get('Content-Type', 'application/json'))
content_type = response['headers'].pop(
'Content-Type', 'application/json')
self.send_header('Content-Type', content_type)
headers = response['headers']
for header in headers:
self.send_header(header, headers[header])
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_local.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from chalice import local, BadRequestError
from chalice import Response
import json
import decimal
import pytest
Expand Down Expand Up @@ -66,6 +67,12 @@ def decimals():
def query_string():
return demo.current_request.query_params

@demo.route('/custom-response')
def custom_response():
return Response(body='text',
status_code=200,
headers={'Content-Type': 'text/plain'})

return demo


Expand Down Expand Up @@ -187,6 +194,16 @@ def test_querystring_is_mapped(handler):
assert _get_body_from_response_stream(handler) == {'a': 'b', 'c': 'd'}


def test_content_type_included_once(handler):
set_current_request(handler, method='GET', path='/custom-response')
handler.do_GET()
value = handler.wfile.getvalue()
response_lines = value.splitlines()
content_header_lines = [line for line in response_lines
if line.startswith('Content-Type')]
assert len(content_header_lines) == 1


@pytest.mark.parametrize('actual_url,matched_url', [
('/foo', '/foo'),
('/foo/bar', '/foo/bar'),
Expand Down

0 comments on commit 173457d

Please sign in to comment.