psf / requests

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

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

Closed Green360 closed 5 months ago

Green360 commented 5 months ago

I want 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'8\r\n'
    yield b'search=1\r\n'
    yield b'0\r\n'

response = requests.post(url,data=data_chunks(), headers={"Content-Type":"application/x-www-form-urlencoded","Transfer-Encoding":"chunked"}, 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 Accept: / Connection: close Content-Type: application/x-www-form-urlencoded Content-Length: 16

8 search=1 0

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. What am I supposed to do?

github-actions[bot] commented 5 months ago

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