#NEWLINE# def autovary( ignore = None , debug = False ) : #NEWLINE# #INDENT# 'Auto-populate the Vary response header based on request.header access.' #NEWLINE# request = cherrypy . serving . request #NEWLINE# req_h = request . headers #NEWLINE# request . headers = MonitoredHeaderMap ( ) #NEWLINE# request . headers . update ( set_response_header ) #NEWLINE# if ( ignore is None ) : #NEWLINE# #INDENT# ignore = set ( [ 'Content-Disposition' , 'Content-Length' , 'Content-Type' ] ) #NEWLINE# #UNINDENT# def set_response_header( ) : #NEWLINE# #INDENT# resp_h = cherrypy . serving . response . headers #NEWLINE# v = set ( [ e . value for e in resp_h . elements ( 'Vary' ) ] ) #NEWLINE# if debug : #NEWLINE# #INDENT# cherrypy . log ( ( 'Accessed headers: %s' % request . headers . accessed_headers ) , 'TOOLS.AUTOVARY' ) #NEWLINE# #UNINDENT# v = v . union ( request . headers . accessed_headers ) #NEWLINE# v = v . difference ( ignore ) #NEWLINE# v = list ( v ) #NEWLINE# v . sort ( ) #NEWLINE# resp_h [ 'Vary' ] = ', ' . join ( v ) #NEWLINE# #UNINDENT# request . hooks . attach ( 'before_finalize' , set_response_header , 95 )