psf / requests

A simple, yet elegant, HTTP library.
https://requests.readthedocs.io/en/latest/
Apache License 2.0
52.19k stars 9.33k forks source link

requests library seems to ignore "Transfer-Encoding" header #6760

Closed Green360 closed 4 months ago

Green360 commented 4 months ago

I wanted to send a request with "Transfer-Encoding:chunked" but somehow the header is never set. Below is my code for testing and the corresponding captured request.

import requests

url = 'http://[replaced]/test.php'

def data_chunks():
    yield b'7\r\n'
    yield b'param=2\r\n'

response = requests.post(url,data=data_chunks(), headers={"Transfer-Encoding":"chunked", "Content-Type":"application/x-www-form-urlencoded"}, proxies={"http":"http://127.0.0.1:8080"})

POST /test.php HTTP/1.1 Host: [replaced] User-Agent: python-requests/2.28.1 Accept-Encoding: gzip, deflate, br Accept: / Connection: close Content-Length: 12

7 param=2

If I do not set the "Transfer-Encoding" header it is not used and even if I explicitly set the "Transfer-Encoding" header it is not used. The requests library always seems to put a "Content-Length" instead. My goal is to form this request:

POST /test.php HTTP/1.1 Host: [replaced] Transfer-Encoding: chunked Content-Type: application/x-www-form-urlencoded

7 param=2

github-actions[bot] commented 4 months ago

As described in the template, we won't be able to answer questions on this issue tracker. Please use Stack Overflow