Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_http_header_collection_concatenation_with_other_collection():
headers = Headers([
(b'Hello', b'World'),
(b'Svil', b'Power'),
])
with_addition = headers + Headers([(b'Foo', b'foo'), (b'Ufo', b'ufo')])
for name in {b'foo', b'ufo'}:
assert headers[name] == tuple()
example = with_addition[name]
assert len(example) == 1
header = example[0]
assert header == name
def test_iadd_http_header_collection_concatenation_with_collection_of_headers():
headers = Headers([
(b'Hello', b'World'),
(b'Svil', b'Power'),
])
headers += Headers([(b'foo', b'foo'), (b'ufo', b'ufo')])
for name in {b'foo', b'ufo'}:
example = headers[name]
assert len(example) == 1
header = example[0]
assert header == name
def test_iadd_http_header_collection_concatenation_with_collection_of_headers():
headers = Headers([
(b'Hello', b'World'),
(b'Svil', b'Power'),
])
headers += Headers([(b'foo', b'foo'), (b'ufo', b'ufo')])
for name in {b'foo', b'ufo'}:
example = headers[name]
assert len(example) == 1
header = example[0]
assert header == name
def test_http_header_collection_instantiating_with_list_of_tuples(values):
headers = Headers(values)
for input_header in values:
header = headers[input_header[0]]
assert len(header) == 1
assert header[0] == input_header[1]
def test_http_header_collection_item_getter_case_insensitive():
headers = Headers()
headers[b'example'] = b'Hello, World'
header = headers[b'Example']
assert header == (b'Hello, World',)
def test_iadd_http_header_collection_concatenation_with_duplicate_():
headers = Headers([
(b'Hello', b'World'),
(b'Svil', b'Power'),
])
headers += (b'Svil', b'Kitty')
example = headers[b'Svil']
assert len(example) == 2
assert any(x == b'Power' for x in example)
assert any(x == b'Kitty' for x in example)
def test_http_header_collection_instantiating_with_list_of_headers_repeated_values(values):
headers = Headers(values)
for input_header in values:
input_headers_with_same_name = [x[1] for x in values if x[0] == input_header[0]]
header = headers[input_header[0]]
assert len(header) == len(input_headers_with_same_name)
assert any(x == y for x in header for y in input_headers_with_same_name)
def test_http_header_collection_add_many_items():
headers = Headers()
values = {
b'A': b'B',
b'C': b'D',
b'E': b'F',
}
headers.add_many(values)
for key, value in values.items():
header = headers.get_single(key)
assert header is not None
assert header == value
async def frozen_file_getter(request):
previous_etag = request.if_none_match
if previous_etag and previous_etag == current_etag:
return Response(304, headers, None)
if request.method == 'HEAD':
return Response(200, head_headers, None)
return Response(200, Headers(headers), Content(mime, data))
return frozen_file_getter