Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix connection reset when over max content size
the current version of werkzeug fails to exhaust the input stream when it detects that the content exceeds the configured max size. when run with gunicorn, the stream is never exhausted which leads to firefox (and others) reporting a connection reset as they receive the response without the body being uploaded. here's a sample application: ```python from flask import Flask, request, redirect, url_for class Config: SECRET_KEY = 'foo' MAX_CONTENT_LENGTH = 1024 * 1024 * 1 app = Flask(__name__) app.config.from_object(Config) @app.route('/') def index(): return '''\ <!doctype html> <html> <head> <title>File Upload</title> </head> <body> <h1>File Upload</h1> <form method="POST" action="" enctype="multipart/form-data"> <p><input type="file" name="file"></p> <p><input type="submit" value="Submit"></p> </form> </body> </html> ''' @app.route('/', methods=['POST']) def upload_file(): request.files['file'] print('uploaded!') return redirect(url_for('index')) ``` when run with gunicorn: ```bash strace -f gunicorn --bind 127.0.0.1:8080 app:app --access-logfile - 2> log ``` the strace indicates the following happens: ``` [pid 24372] recvfrom(9, "POST / HTTP/1.1\r\nHost: localhost"..., 8192, 0, NULL, NULL) = 8192 ... [pid 24372] sendto(9, "HTTP/1.1 413 REQUEST ENTITY TOO "..., 183, 0, NULL, 0) = 183 [pid 24372] sendto(9, "<!DOCTYPE HTML PUBLIC \"-//W3C//D"..., 196, 0, NULL, 0) = 196 ``` in this, werkzeug reads the first 8KB of the request, but then never any more and starts sending the response after the fix, werkzeug reads the entire input (and discards it) before sending a response
- Loading branch information