Fix remove_entity_headers helper function (#1415)

* Fix `remove_entity_headers` helper function

* Add test for `remove_entity_headers` helper function
This commit is contained in:
Hasan Ramezani 2018-11-19 16:30:53 +01:00 committed by Stephen Sadowski
parent 096c44b910
commit f7adc5f84c
2 changed files with 39 additions and 1 deletions

View File

@ -128,6 +128,6 @@ def remove_entity_headers(headers, allowed=("content-location", "expires")):
headers = { headers = {
header: value header: value
for header, value in headers.items() for header, value in headers.items()
if not is_entity_header(header) and header.lower() not in allowed if not is_entity_header(header) or header.lower() in allowed
} }
return headers return headers

View File

@ -34,3 +34,41 @@ def test_is_hop_by_hop_header():
) )
for header, expected in tests: for header, expected in tests:
assert helpers.is_hop_by_hop_header(header) is expected assert helpers.is_hop_by_hop_header(header) is expected
def test_remove_entity_headers():
tests = (
(
{},
{}
),
(
{
"Allow": "GET, POST, HEAD",
},
{}
),
(
{
"Content-Type": "application/json",
"Expires": "Wed, 21 Oct 2015 07:28:00 GMT",
"Foo": "Bar"
},
{
"Expires": "Wed, 21 Oct 2015 07:28:00 GMT",
"Foo": "Bar"
},
),
(
{
"Allow": "GET, POST, HEAD",
"Content-Location": "/test"
},
{
"Content-Location": "/test"
},
),
)
for header, expected in tests:
assert helpers.remove_entity_headers(header) == expected