forked from orbit-oss/flask
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.
This commit is contained in:
parent
8d7ca29a35
commit
06b224676d
2 changed files with 34 additions and 3 deletions
|
|
@ -495,7 +495,8 @@ def send_from_directory(directory, filename, **options):
|
|||
filename = safe_join(directory, filename)
|
||||
if not os.path.isfile(filename):
|
||||
raise NotFound()
|
||||
return send_file(filename, conditional=True, **options)
|
||||
options.setdefault('conditional', True)
|
||||
return send_file(filename, **options)
|
||||
|
||||
|
||||
def get_root_path(import_name):
|
||||
|
|
@ -651,6 +652,11 @@ class _PackageBoundObject(object):
|
|||
return FileSystemLoader(os.path.join(self.root_path,
|
||||
self.template_folder))
|
||||
|
||||
def get_static_file_options(self, filename):
|
||||
"""Function used internally to determine what keyword arguments
|
||||
to send to :func:`send_from_directory` for a specific file."""
|
||||
return {}
|
||||
|
||||
def send_static_file(self, filename):
|
||||
"""Function used internally to send static files from the static
|
||||
folder to the browser.
|
||||
|
|
@ -659,7 +665,8 @@ class _PackageBoundObject(object):
|
|||
"""
|
||||
if not self.has_static_folder:
|
||||
raise RuntimeError('No static folder for this object')
|
||||
return send_from_directory(self.static_folder, filename)
|
||||
return send_from_directory(self.static_folder, filename,
|
||||
**self.get_static_file_options(filename))
|
||||
|
||||
def open_resource(self, resource, mode='rb'):
|
||||
"""Opens a resource from the application's resource folder. To see
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue