From 14f56363a4992506f2b3670985fca4f0a29e5176 Mon Sep 17 00:00:00 2001 From: David Lord Date: Fri, 29 Jan 2021 10:44:46 -0800 Subject: [PATCH] rename send_file add_etags to etag --- CHANGES.rst | 3 ++- src/flask/helpers.py | 24 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8111d3ef..78951681 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -49,7 +49,8 @@ Unreleased implementations in ``werkzeug.utils``. :pr:`3828` - Some ``send_file`` parameters have been renamed, the old names are deprecated. ``attachment_filename`` is renamed to ``download_name``. - ``cache_timeout`` is renamed to ``max_age``. :pr:`3828` + ``cache_timeout`` is renamed to ``max_age``. ``add_etags`` is + renamed to ``etag``. :pr:`3828, 3883` - ``send_file`` passes ``download_name`` even if ``as_attachment=False`` by using ``Content-Disposition: inline``. :pr:`3828` diff --git a/src/flask/helpers.py b/src/flask/helpers.py index 325ac981..85277407 100644 --- a/src/flask/helpers.py +++ b/src/flask/helpers.py @@ -439,6 +439,8 @@ def get_flashed_messages(with_categories=False, category_filter=()): def _prepare_send_file_kwargs( download_name=None, attachment_filename=None, + etag=None, + add_etags=None, max_age=None, cache_timeout=None, **kwargs, @@ -461,12 +463,22 @@ def _prepare_send_file_kwargs( ) max_age = cache_timeout + if add_etags is not None: + warnings.warn( + "The 'add_etags' parameter has been renamed to 'etag'. The old name will be" + " removed in Flask 2.1.", + DeprecationWarning, + stacklevel=3, + ) + etag = add_etags + if max_age is None: max_age = current_app.get_send_file_max_age kwargs.update( environ=request.environ, download_name=download_name, + etag=etag, max_age=max_age, use_x_sendfile=current_app.use_x_sendfile, response_class=current_app.response_class, @@ -482,7 +494,8 @@ def send_file( download_name=None, attachment_filename=None, conditional=True, - add_etags=True, + etag=True, + add_etags=None, last_modified=None, max_age=None, cache_timeout=None, @@ -518,8 +531,8 @@ def send_file( the file. Defaults to the passed file name. :param conditional: Enable conditional and range responses based on request headers. Requires passing a file path and ``environ``. - :param add_etags: Calculate an ETag for the file. Requires passing a - file path. + :param etag: Calculate an ETag for the file, which requires passing + a file path. Can also be a string to use instead. :param last_modified: The last modified time to send for the file, in seconds. If not provided, it will try to detect it from the file path. @@ -537,6 +550,10 @@ def send_file( ``conditional`` is enabled and ``max_age`` is not set by default. + .. versionchanged:: 2.0.0 + ``etag`` replaces the ``add_etags`` parameter. It can be a + string to use instead of generating one. + .. versionchanged:: 2.0 Passing a file-like object that inherits from :class:`~io.TextIOBase` will raise a :exc:`ValueError` rather @@ -593,6 +610,7 @@ def send_file( download_name=download_name, attachment_filename=attachment_filename, conditional=conditional, + etag=etag, add_etags=add_etags, last_modified=last_modified, max_age=max_age,