def test_remove_content_length_if_compression_enabled_on_payload_http10(): writer = mock.Mock() def write_headers(status_line, headers): assert hdrs.CONTENT_LENGTH not in headers assert hdrs.TRANSFER_ENCODING not in headers writer.write_headers.side_effect = write_headers req = make_request('GET', '/', version=HttpVersion10, payload_writer=writer) resp = Response(body=BytesPayload(b'answer')) resp.enable_compression(ContentCoding.gzip) yield from resp.prepare(req) assert resp.content_length is None
async def test_rm_content_length_if_compression_http11() -> None: writer = mock.Mock() async def write_headers(status_line, headers): assert hdrs.CONTENT_LENGTH not in headers assert headers.get(hdrs.TRANSFER_ENCODING, "") == "chunked" writer.write_headers.side_effect = write_headers req = make_request("GET", "/", writer=writer) payload = BytesPayload(b"answer", headers={"X-Test-Header": "test"}) resp = Response(body=payload) assert resp.content_length == 6 resp.body = payload resp.enable_compression(ContentCoding.gzip) await resp.prepare(req) assert resp.content_length is None
def test_remove_content_length_if_compression_enabled_on_payload_http11(): writer = mock.Mock() def write_headers(status_line, headers): assert hdrs.CONTENT_LENGTH not in headers assert headers.get(hdrs.TRANSFER_ENCODING, '') == 'chunked' writer.write_headers.side_effect = write_headers req = make_request('GET', '/', payload_writer=writer) payload = BytesPayload(b'answer', headers={"X-Test-Header": "test"}) resp = Response(body=payload) assert resp.content_length == 6 resp.body = payload resp.enable_compression(ContentCoding.gzip) yield from resp.prepare(req) assert resp.content_length is None