diff --git a/doc/site/configuration.rst b/doc/site/configuration.rst index 5bf260c4..358e2d94 100644 --- a/doc/site/configuration.rst +++ b/doc/site/configuration.rst @@ -21,6 +21,7 @@ Example gunicorn.conf.py user = None # Change process owner to user group = None # Change process group to group proc_name = None # Change the process name + tmp_upload_dir = None # Set path used to store temporary uploads def after_fork(server, worker): fmt = "worker=%s spawned pid=%s" @@ -74,3 +75,6 @@ umask: user: The user as which worker processes will by launched. + +tmp_upload_dir: + Set the path used to store temporarily the body of the request. \ No newline at end of file diff --git a/gunicorn/config.py b/gunicorn/config.py index 12b318be..58ba7030 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -25,6 +25,7 @@ class Config(object): umask="0", user=None, group=None, + tmp_upload_dir=None, after_fork=lambda server, worker: server.log.info( "Worker spawned (pid: %s)" % worker.pid), diff --git a/gunicorn/http/request.py b/gunicorn/http/request.py index 4be36a82..9dba66a6 100644 --- a/gunicorn/http/request.py +++ b/gunicorn/http/request.py @@ -36,8 +36,9 @@ class Request(object): "SERVER_SOFTWARE": "gunicorn/%s" % __version__ } - def __init__(self, socket, client_address, server_address, debug=False): - self.debug = debug + def __init__(self, socket, client_address, server_address, conf): + self.debug = conf['debug'] + self.conf = conf self.socket = socket self.client_address = client_address @@ -73,7 +74,7 @@ class Request(object): if not self.parser.content_len and not self.parser.is_chunked: wsgi_input = StringIO.StringIO() else: - wsgi_input = TeeInput(self.socket, self.parser, buf[i:]) + wsgi_input = TeeInput(self.socket, self.parser, buf[i:], self.conf) # This value should evaluate true if an equivalent application # object may be simultaneously invoked by another process, and diff --git a/gunicorn/http/tee.py b/gunicorn/http/tee.py index fd476cdb..82e5c449 100644 --- a/gunicorn/http/tee.py +++ b/gunicorn/http/tee.py @@ -19,7 +19,8 @@ from gunicorn.util import MAX_BODY, CHUNK_SIZE, read_partial class TeeInput(object): - def __init__(self, socket, parser, buf): + def __init__(self, socket, parser, buf, conf): + self.conf = conf self.buf = buf self.parser = parser self.socket = socket @@ -28,7 +29,8 @@ class TeeInput(object): if self._len and self._len < MAX_BODY: self.tmp = StringIO.StringIO() else: - self.tmp = tempfile.TemporaryFile() + self.tmp = tempfile.TemporaryFile( + dir=self.conf['tmp_upload_dir']) if len(buf) > 0: chunk, self.buf = parser.filter_body(buf) diff --git a/gunicorn/worker.py b/gunicorn/worker.py index dd3dd485..346ffc92 100644 --- a/gunicorn/worker.py +++ b/gunicorn/worker.py @@ -143,7 +143,7 @@ class Worker(object): def handle(self, client, addr): util.close_on_exec(client) try: - req = http.Request(client, addr, self.address, self.debug) + req = http.Request(client, addr, self.address, self.conf) try: response = self.app(req.read(), req.start_response)