Created
January 15, 2016 15:39
-
-
Save allanlei/4436734817b01d4a395e to your computer and use it in GitHub Desktop.
Vary decorator for Flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from __future__ import absolute_import, division, print_function, unicode_literals | |
from flask import after_this_request | |
import decorator | |
def vary(*headers): | |
def _vary(f, *args, **kwargs): | |
@after_this_request | |
def zipper(response): | |
response.vary = ' '.join( | |
set(response.headers.get('Vary', '').split() + list(headers))) | |
return response | |
return f(*args, **kwargs) | |
return decorator.decorator(_vary) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment