You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
404 responses (or any response sent by the server prior to the entire request being sent) for chunk-encoded requests may not be received by the caller.
This appears to happen if the server closes the connection (after sending the 404 response) prior to the completion of the chunked post / upload.
Expected Result
Posting a chunked encoded request to an invalid URL should return the 404 response.
Actual Result
A requests.exceptions.ConnectionError: [Errno 32] Broken pipe error is raised instead.
Reproduction Steps
A minimal server using flask is given below:
#!/usr/bin/env python3
import sys
from flask import Flask, request
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
@app.route('/post_endpoint', methods=['POST'])
def post_normal_response():
for line in request.stream:
str_line = line.decode('utf-8')
sys.stdout.write(str_line)
sys.stdout.flush()
return 'OK'
if __name__ == '__main__':
app.run()
Client code illustrating the problem is:
#!/usr/bin/env python3
from time import sleep
import requests
VALID_URL = 'http://127.0.0.1:5000/post_endpoint'
INVALID_URL = 'http://127.0.0.1:5000/does_not_exist'
LINES = ['Line {}\n'.format(x) for x in range(5)]
DATA = ''.join(LINES).encode('utf-8')
def chunked():
for line in LINES:
sleep(1)
yield line.encode('utf-8')
def test_url(url):
r = requests.post(url, data=DATA)
print(r)
r = requests.post(url, data=chunked())
print(r)
if __name__ == '__main__':
test_url(VALID_URL)
print('-----')
test_url(INVALID_URL)
404 responses (or any response sent by the server prior to the entire request being sent) for chunk-encoded requests may not be received by the caller.
This appears to happen if the server closes the connection (after sending the 404 response) prior to the completion of the chunked post / upload.
Expected Result
Posting a chunked encoded request to an invalid URL should return the 404 response.
Actual Result
A
requests.exceptions.ConnectionError: [Errno 32] Broken pipe
error is raised instead.Reproduction Steps
A minimal server using flask is given below:
Client code illustrating the problem is:
System Information
Patch to address the issue
requests-patch.zip
The text was updated successfully, but these errors were encountered: