mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Add tests to verify that correct 'Content-Length' or 'Transfer-Encoding' headers are being set in PreparedRequest.
This commit is contained in:
committed by
Nate Prewitt
parent
c398ab0e7d
commit
2d2c831d07
@@ -1693,6 +1693,30 @@ class TestRequests:
|
||||
resp.close()
|
||||
assert resp.raw.closed
|
||||
|
||||
def test_empty_stream_with_auth_does_not_set_content_length_header(self, httpbin):
|
||||
"""Ensure that a byte stream with size 0 will not set both a Content-Length
|
||||
and Transfer-Encoding header
|
||||
"""
|
||||
auth = ('user', 'pass')
|
||||
url = httpbin('post')
|
||||
file_obj = io.BytesIO(b'')
|
||||
r = requests.Request('POST', url, auth=auth, data=file_obj)
|
||||
prepared_request = r.prepare()
|
||||
assert 'Transfer-Encoding' in prepared_request.headers
|
||||
assert 'Content-Length' not in prepared_request.headers
|
||||
|
||||
def test_stream_with_auth_does_not_set_transfer_encoding_header(self, httpbin):
|
||||
"""Ensure that a byte stream with size > 0 will not set both a Content-Length
|
||||
and Transfer-Encoding header"""
|
||||
auth = ('user', 'pass')
|
||||
url = httpbin('post')
|
||||
file_obj = io.BytesIO(b'test data')
|
||||
r = requests.Request('POST', url, auth=auth, data=file_obj)
|
||||
prepared_request = r.prepare()
|
||||
assert 'Transfer-Encoding' not in prepared_request.headers
|
||||
assert 'Content-Length' in prepared_request.headers
|
||||
|
||||
|
||||
class TestCaseInsensitiveDict:
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
|
||||
Reference in New Issue
Block a user