Skip to content
Myr

support timedelta for SEND_FILE_MAX_AGE_DEFAULT config variable

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Timo Furrer · committed by Timo Furrer · parent 1ac4156 · Browse files · 5 files+36 added−7 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+36 added−7 removed

  • tests:+9 added−0 removed
  • other:+27 added−7 removed

5 files+36 added−7 removed

modified:docs/config.rst+2 added-1 removed
128 unmodified lines
129 returning a 413 status code.130``SEND_FILE_MAX_AGE_DEFAULT`` Default cache control max age to use with131 :meth:`~flask.Flask.send_static_file` (the132 default static file handler) and133 :func:`~flask.send_file`, in133 :func:`~flask.send_file`, as134 :class:`datetime.timedelta` or as seconds.135 seconds. Override this value on a per-file136 basis using the137 :meth:`~flask.Flask.get_send_file_max_age`138 hook on :class:`~flask.Flask` or
325 unmodified lines
modified:flask/app.py+11 added-1 removed
244 unmodified lines
245 #: ``timedelta(days=31)``246 permanent_session_lifetime = ConfigAttribute('PERMANENT_SESSION_LIFETIME',247 get_converter=_make_timedelta)248249 #: A :class:`~datetime.timedelta` which is used as default cache_timeout250 #: for the :func:`send_file` functions. The default is 12 hours.251 #:252 #: This attribute can also be configured from the config with the253 #: ``SEND_FILE_MAX_AGE_DEFAULT`` configuration key. This configuration254 #: variable can also be set with an integer value used as seconds.255 #: Defaults to ``timedelta(hours=12)``256 send_file_max_age_default = ConfigAttribute('SEND_FILE_MAX_AGE_DEFAULT',257 get_converter=_make_timedelta)258259 #: Enable this if you want to use the X-Sendfile feature. Keep in260 #: mind that the server has to support this. This only affects files261 #: sent with the :func:`send_file` method.262 #:
43 unmodified lines
306 'SESSION_COOKIE_HTTPONLY': True,307 'SESSION_COOKIE_SECURE': False,308 'SESSION_REFRESH_EACH_REQUEST': True,309 'MAX_CONTENT_LENGTH': None,300 'SEND_FILE_MAX_AGE_DEFAULT': 12 * 60 * 60, # 12 hours310 'SEND_FILE_MAX_AGE_DEFAULT': timedelta(hours=12),311 'TRAP_BAD_REQUEST_ERRORS': False,312 'TRAP_HTTP_EXCEPTIONS': False,313 'EXPLAIN_TEMPLATE_LOADING': False,314 'PREFERRED_URL_SCHEME': 'http',
1671 unmodified lines
modified:flask/helpers.py+13 added-1 removed
12 unmodified lines
13import sys14import pkgutil15import posixpath16import mimetypes17from datetime import timedelta18from time import time19from zlib import adler3220from threading import RLock21from werkzeug.routing import BuildError
834 unmodified lines
856 return flask.Flask.get_send_file_max_age(self, name)857858 .. versionadded:: 0.9859 """859 return current_app.config['SEND_FILE_MAX_AGE_DEFAULT']860 return total_seconds(current_app.send_file_max_age_default)861862 def send_static_file(self, filename):863 """Function used internally to send static files from the static864 folder to the browser.
33 unmodified lines
898 """899 if mode not in ('r', 'rb'):900 raise ValueError('Resources can only be opened for reading')901 return open(os.path.join(self.root_path, resource), mode)902903904def total_seconds(td):905 """Returns the total seconds from a timedelta object.906907 :param timedelta td: the timedelta to be converted in seconds908909 :returns: number of seconds910 :rtype: int911 """912 return td.days * 60 * 60 * 24 + td.seconds
modified:flask/sessions.py+1 added-4 removed
15 unmodified lines
16from werkzeug.http import http_date, parse_date17from werkzeug.datastructures import CallbackDict18from . import Markup, json19from ._compat import iteritems, text_type20from .helpers import total_seconds2122from itsdangerous import URLSafeTimedSerializer, BadSignature232424def total_seconds(td):25 return td.days * 60 * 60 * 24 + td.seconds262725class SessionMixin(object):26 """Expands a basic dictionary with an accessors that are expected27 by Flask extensions and users for the session.28 """
334 unmodified lines
modified:tests/test_config.py+9 added
8 unmodified lines
910import pytest1112import os13from datetime import timedelta14import flask151617# config keys used for the TestConfig
150 unmodified lines
168 app.config['PERMANENT_SESSION_LIFETIME'] = 42169 assert app.permanent_session_lifetime.seconds == 42170171172def test_send_file_max_age():173 app = flask.Flask(__name__)174 app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 3600175 assert app.send_file_max_age_default.seconds == 3600176 app.config['SEND_FILE_MAX_AGE_DEFAULT'] = timedelta(hours=2)177 assert app.send_file_max_age_default.seconds == 7200178179180def test_get_namespace():181 app = flask.Flask(__name__)182 app.config['FOO_OPTION_1'] = 'foo option 1'183 app.config['FOO_OPTION_2'] = 'foo option 2'
18 unmodified lines