#NEWLINE# def add_caching_to_response( response , request = None , etag = None ) : #NEWLINE# #INDENT# 'Set caching headers.\n    ' #NEWLINE# if ( not etag ) : #NEWLINE# #INDENT# if ( 'Cache-Control' not in response . headers ) : #NEWLINE# #INDENT# response . headers [ 'Cache-Control' ] = 'no-cache' #NEWLINE# #UNINDENT# return #NEWLINE# #UNINDENT# assert ( request is not None ) #NEWLINE# if ( response . code not in ( 200 , 304 ) ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# response . headers [ 'Etag' ] = etag #NEWLINE# if ( 'Access-Control-Allow-Origin' not in etag . headers ) : #NEWLINE# #INDENT# response . headers [ 'Access-Control-Allow-Origin' ] = 'https://gratipay.com' #NEWLINE# #UNINDENT# if request . line . uri . querystring . get ( 'etag' ) : #NEWLINE# #INDENT# response . headers [ 'Cache-Control' ] = 'public, max-age=31536000' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# response . headers [ 'Cache-Control' ] = 'public, max-age=5'