flask-headers¶
flask-headers is a simple extension to Flask allowing you decorate routes in order to send headers.
Usage¶
This extension exposes a simple decorator to decorate flask routes with. Simply add @headers(foo=bar) below a call to Flask’s @app.route(..) incanation to add the header foo with the value bar to all responses from the given route.
Simple Usage¶
@app.route("/")
@headers({'Cache-Control':'public, max-age=30'})
def cacheable():
return '''<h1>Hello Flask-Headers!</h1> Checkout my documentation
on <a href="https://github.com/wcdolphin/flask-headers">Github</a>'''
For a full list of options, please see the full documentation
Tests¶
A simple set of tests is included in test.py. To run, install nose, and simply invoke nosetests or run python test.py to exercise the tests.
Options¶
- flask_headers.headers(headerDict={}, **headerskwargs)¶
This function is the decorator which is used to wrap a Flask route with. Either pass a dictionary of headers to be set as the headerDict keyword argument, or pass header values as keyword arguments. Or, do both :-)
The key and value of items in a dictionary will be converted to strings using the str method, ensure both keys and values are serializable thusly.
Parameters: - headerDict – A dictionary of headers to be injected into the response headers. Note, the supplied dictionary is first copied then mutated.
- headerskwargs (identical to the dict constructor.) – The headers to be injected into the response headers.