Introduced a method to adjust static file cache-control headers based on filename #433

Merged
merged 1 commit into from Mar 13, 2012

Conversation

2 participants
@dave-shawley
Contributor

dave-shawley commented Mar 12, 2012

I needed this method to adjust the cache control headers for .js files that one of my applications was statically serving. The default expiration is buried in an argument to send_file and is set to 12 hours. There was no good way to adjust this value previously. So I added a new method to _PackageBoundObject named get_static_file_options that returns a dict (empty by default) of keywords to pass into send_file. This can be overridden in the flask.Flask derivative to adjust values based on the debug flag or filename.

Added _PackageBoundObject.get_static_file_options.
This method receives the name of a static file that is going to be served
up and generates a dict of options to use when serving the file.  The
default set is empty so code will fall back to the existing behavior if
the method is not overridden.

I needed this method to adjust the cache control headers for .js files that
one of my applications was statically serving.  The default expiration is
buried in an argument to send_file and is set to 12 hours.  There was no
good way to adjust this value previously.

rduplain added a commit that referenced this pull request Mar 13, 2012

Merge pull request #433 from dave-shawley/master
Introduced a method to adjust static file cache-control headers based on filename

@rduplain rduplain merged commit f4a31db into pallets:master Mar 13, 2012

rduplain added a commit that referenced this pull request Mar 13, 2012

rduplain added a commit that referenced this pull request Mar 13, 2012

Expose send_file max-age as config value, #433.
Need to add the same hook in a Blueprint, but this is the first such
case where we need app.config in the Blueprint.
@rduplain

This comment has been minimized.

Show comment Hide comment
@rduplain

rduplain Apr 9, 2012

Contributor

This is now fully configurable through SEND_FILE_MAX_AGE_DEFAULT for both Flask and Blueprint static files. Thanks @dave-shawley for introducing this thread of changes.

Contributor

rduplain commented Apr 9, 2012

This is now fully configurable through SEND_FILE_MAX_AGE_DEFAULT for both Flask and Blueprint static files. Thanks @dave-shawley for introducing this thread of changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment