From d5a07ce4ffb0801b24b5fcd407585e219e8b6b0b Mon Sep 17 00:00:00 2001 From: benoitc Date: Sat, 21 May 2016 11:06:51 +0200 Subject: [PATCH] Allow disabling sendfile via an environment variable add support for the `SENDFILE` environment variable. fix #1252 --- gunicorn/config.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gunicorn/config.py b/gunicorn/config.py index b0227ccc..af63407c 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -192,6 +192,17 @@ class Config(object): return env + @property + def sendfile(self): + if self.settings['sendfile'].get() is not None: + return False + + if 'SENDFILE' in os.environ: + sendfile = os.environ['SENDFILE'].lower() + return sendfile in ['y', '1', 'yes', 'true'] + + return True + class SettingMeta(type): def __new__(cls, name, bases, attrs): @@ -836,13 +847,19 @@ class Sendfile(Setting): validator = validate_bool action = "store_const" const = False + desc = """\ Disables the use of ``sendfile()``. + If not set, the value of the ``SENDFILE`` environment variable is used + to enable or disable its usage. + .. versionadded:: 19.2 .. versionchanged:: 19.4 Swapped ``--sendfile`` with ``--no-sendfile`` to actually allow disabling. + .. versionchanged:: 19.6 + added support for the ``SENDFILE`` environment variable """