Skip to content

Commit

Permalink
adding in enforce_content_length=True default and test
Browse files Browse the repository at this point in the history
  • Loading branch information
nateprewitt committed Sep 8, 2016
1 parent b2f6173 commit d356e0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 5 additions & 2 deletions requests/adapters.py
Expand Up @@ -420,7 +420,8 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
preload_content=False,
decode_content=False,
retries=self.max_retries,
timeout=timeout
timeout=timeout,
enforce_content_length=True
)

# Send the request.
Expand Down Expand Up @@ -464,7 +465,9 @@ def send(self, request, stream=False, timeout=None, verify=True, cert=None, prox
pool=conn,
connection=low_conn,
preload_content=False,
decode_content=False
decode_content=False,
enforce_content_length=True,
request_method=request.method
)
except:
# If we hit any problems here, clean up the connection.
Expand Down
10 changes: 10 additions & 0 deletions tests/test_requests.py
Expand Up @@ -113,6 +113,16 @@ def test_override_content_length(self, httpbin):
assert 'Content-Length' in r.headers
assert r.headers['Content-Length'] == 'not zero'

@pytest.mark.skip(reason='Can\'t test till urllib3 1.17 is merged.')
def test_incorrect_content_length(self, httpbin):
from requests.packages.urllib3.exceptions import IncompleteRead
params = {'Content-Length': 300}
r = requests.Request('GET', httpbin('response-headers')).prepare()
s = requests.Sesssion()
with pytest.raises(IncompleteRead):
resp = s.send(r)
assert s.send(r, enforce_content_length=False) is not None

def test_path_is_not_double_encoded(self):
request = requests.Request('GET', "http://0.0.0.0/get/test case").prepare()

Expand Down

0 comments on commit d356e0e

Please sign in to comment.