Skip to content
Myr

Send only one Host header in chunked request

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

Closes #5274

authored by hodbn · committed by Nate Prewitt · parent aae7801 · Browse files · 3 files+30 added−1 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+30 added−1 removed

  • tests:+27 added−0 removed
  • other:+3 added−1 removed

3 files+30 added−1 removed

modified:requests/adapters.py+2 added-1 removed
458 unmodified lines
459460 try:461 low_conn.putrequest(request.method,462 url,463 skip_accept_encoding=True)463 skip_accept_encoding=True,464 skip_host='Host' in request.headers)465466 for header, value in request.headers.items():467 low_conn.putheader(header, value)468
69 unmodified lines
modified:tests/test_lowlevel.py+27 added
44 unmodified lines
45 r = requests.get(url)46 close_server.set() # release server block474849def test_chunked_upload_uses_only_specified_host_header():50 """Ensure we use only the specified Host header for chunked requests."""51 text_200 = (b'HTTP/1.1 200 OK\r\n'52 b'Content-Length: 0\r\n\r\n')53 wanted_host = 'sample-host'54 expected_header = 'Host: {}'.format(wanted_host).encode('utf-8')55 def single_host_resp_handler(sock):56 request_content = consume_socket_content(sock, timeout=0.5)57 assert expected_header in request_content58 assert request_content.count(b'Host: ') == 159 sock.send(text_200)6061 return request_content6263 close_server = threading.Event()6465 server = Server(single_host_resp_handler, wait_to_close_event=close_server)66 data = iter([b'a', b'b', b'c'])6768 with server as (host, port):69 url = 'http://{}:{}/'.format(host, port)70 r = requests.post(url, data=data, headers={'Host': wanted_host}, stream=True)71 close_server.set() # release server block7273 assert r.status_code == 200747576def test_conflicting_content_lengths():77 """Ensure we correctly throw an InvalidHeader error if multiple78 conflicting Content-Length headers are returned.79 """
305 unmodified lines
modified:AUTHORS.rst+1 added
189 unmodified lines
190- Antti Kaihola (`@akaihola <https://github.com/akaihola>`_)191- "Dull Bananas" <dull.bananas0@gmail.com> (`@dullbananas <https://github.com/dullbananas>`_)192- Alessio Izzo (`@aless10 <https://github.com/aless10>`_)193- Sylvain Marié (`@smarie <https://github.com/smarie>`_)194- Hod Bin Noon (`@hodbn <https://github.com/hodbn>`_)