Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set gunicorn limit_request_line parameter over 8190?

I need to POST a large text fragment to a web application through Gunicorn. But Gunicorn rejects requests that have request lines longer than 8190 bytes.

This constant is hardcoded here and used here.

How can I redefine this behavior?

like image 934
Roosh Avatar asked Nov 16 '16 06:11

Roosh


1 Answers

If you set the value to zero, Gunicorn treats it as unlimited. From the docs:

limit_request_line

  • --limit-request-line INT
  • 4094

The maximum size of HTTP request line in bytes.

This parameter is used to limit the allowed size of a client's HTTP request-line. Since the request-line consists of the HTTP method, URI, and protocol version, this directive places a restriction on the length of a request-URI allowed for a request on the server. A server needs this value to be large enough to hold any of its resource names, including any information that might be passed in the query part of a GET request. Value is a number from 0 (unlimited) to 8190.

This parameter can be used to prevent any DDOS attack.

If you need to set it to some value higher than 8190, you'll have to change the source code or build a simple wrapper around Gunicorn's main script that patches the value (although since this uses an internal API, you risk breaking things when upgrading):

# patched_gunicorn_runner.py

from gunicorn.http import message
message.MAX_REQUEST_LINE = 2**16 - 2

from gunicorn.app.wsgiapp import run
run()
like image 58
Blender Avatar answered Nov 05 '22 06:11

Blender