#NEWLINE# def patch_response_headers( response , cache_timeout = None ) : #NEWLINE# #INDENT# "\n    Adds some useful headers to the given HttpResponse object:\n        ETag, Last-Modified, Expires and Cache-Control\n\n    Each header is only added if it isn't already set.\n\n    cache_timeout is in seconds. The CACHE_MIDDLEWARE_SECONDS setting is used\n    by default.\n    " #NEWLINE# if ( cache_timeout is None ) : #NEWLINE# #INDENT# cache_timeout = settings . CACHE_MIDDLEWARE_SECONDS #NEWLINE# #UNINDENT# if ( cache_timeout < 0 ) : #NEWLINE# #INDENT# cache_timeout = 0 #NEWLINE# #UNINDENT# if ( settings . USE_ETAGS and ( not response . has_header ( 'ETag' ) ) ) : #NEWLINE# #INDENT# response [ 'ETag' ] = ( '"%s"' % md5_constructor ( response . content ) . hexdigest ( ) ) #NEWLINE# #UNINDENT# if ( not response . has_header ( 'Last-Modified' ) ) : #NEWLINE# #INDENT# response [ 'Last-Modified' ] = http_date ( ) #NEWLINE# #UNINDENT# if ( not response . has_header ( 'Expires' ) ) : #NEWLINE# #INDENT# response [ 'Expires' ] = http_date ( ( time . time ( ) + cache_timeout ) ) #NEWLINE# #UNINDENT# patch_cache_control ( response , max_age = cache_timeout )