A reset TCP connection occurs when a WSGI application responds before consuming a medium ['wsgi.input']

For my web service, I wrote some logic to prevent multipart/form-dataPOSTs more than, say, 4mb.

This boils down to the following (I removed all use of WebOb and simply reduced it to simple vanilla WSGI code):

import paste.httpserver

form = """\
<html>
<body>
  <form method="post" enctype="multipart/form-data" action="/">
    <input type="file" name="photopicker" />
    <input type="submit" />
  </form>
</body>
</html>
"""

limit = 4 * 1024 * 1024

def upload_app(environ, start_response):
    if environ['REQUEST_METHOD'] == 'POST':
        if int(environ.get('CONTENT_LENGTH', '0')) > limit:
            start_response('400 Ouch', [('content-type', 'text/plain')])
            return ["Upload is too big!"]
    # elided: consume the file appropriately
    start_response('200 OK', [('content-type', 'text/html')])
    return [form]

paste.httpserver.serve(upload_app, port=7007)

The logic shown works correctly when testing a device. But as soon as I tried to send actual files larger than 4 MB in size to this endpoint, I received such errors on the client side:

  • Error 101 (net::ERR_CONNECTION_RESET): Unknown error. from google chrome
  • The connection to the server was reset while the page was loading. from firefox

The same error occurs when using the wsgirefPython built-in HTTP server .

: environ['wsgi.input'].read() HTTP 400, reset . , . , , .

HTTP: , TCP- HTTP- . , close -ing shutdown, .

, - , . - ?

. .

+3
1

, , , . , , , .

, , .

Javascript . , , , , Javascript , .

0

Source: https://habr.com/ru/post/1729189/


All Articles