Skip to content
Myr

Merge pull request #4240 from mgasvoda/master

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Adding header name to exception

authored by Cory Benfield · committed by GitHub · parents 1c2022c, d528106 · Browse files · 3 files+9 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+9 added−5 removed

  • tests:+6 added−3 removed
  • other:+3 added−2 removed

3 files+9 added−5 removed

modified:requests/utils.py+2 added-2 removed
866 unmodified lines
867 try:868 if not pat.match(value):869 raise InvalidHeader("Invalid return character or leading space in header: %s" % name)870 except TypeError:871 raise InvalidHeader("Header value %s must be of type str or bytes, "872 "not %s" % (value, type(value)))871 raise InvalidHeader("Value for header {%s: %s} must be of type str or "872 "bytes, not %s" % (name, value, type(value)))873874875def urldefragauth(url):876 """
28 unmodified lines
modified:tests/test_requests.py+6 added-3 removed
1399 unmodified lines
1400 headers_dict = {'bar': {'foo': 'bar'}}1401 headers_list = {'baz': ['foo', 'bar']}14021403 # Test for int1404 with pytest.raises(InvalidHeader):1404 with pytest.raises(InvalidHeader) as excinfo:1405 r = requests.get(httpbin('get'), headers=headers_int)1406 assert 'foo' in str(excinfo.value)1407 # Test for dict1407 with pytest.raises(InvalidHeader):1408 with pytest.raises(InvalidHeader) as excinfo:1409 r = requests.get(httpbin('get'), headers=headers_dict)1410 assert 'bar' in str(excinfo.value)1411 # Test for list1410 with pytest.raises(InvalidHeader):1412 with pytest.raises(InvalidHeader) as excinfo:1413 r = requests.get(httpbin('get'), headers=headers_list)1414 assert 'baz' in str(excinfo.value)14151416 def test_header_no_return_chars(self, httpbin):1417 """Ensure that a header containing return character sequences raise an1418 exception. Otherwise, multiple headers are created from single string.
971 unmodified lines
modified:HISTORY.rst+1 added
5 unmodified lines
6dev7+++89**Improvements**10- Error messages for invalid headers now include the header name for easier debugging1112**Bugfixes**1314**Dependencies**
1514 unmodified lines