<s> import time <EOL> from django . conf import settings <EOL> from django . utils . cache import patch_vary_headers <EOL> from django . utils . http import cookie_date <EOL> from django . utils . importlib import import_module <EOL> class SessionMiddleware ( object ) : <EOL> def process_request ( self , request ) : <EOL> engine = import_module ( settings . SESSION_ENGINE ) <EOL> session_key = request . COOKIES . get ( settings . SESSION_COOKIE_NAME , None ) <EOL> request . session = engine . SessionStore ( session_key ) <EOL> def process_response ( self , request , response ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> accessed = request . session . accessed <EOL> modified = request . session . modified <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> if accessed : <EOL> patch_vary_headers ( response , ( '<STR_LIT>' , ) ) <EOL> if modified or settings . SESSION_SAVE_EVERY_REQUEST : <EOL> if request . session . get_expire_at_browser_close ( ) : <EOL> max_age = None <EOL> expires = None <EOL> else : <EOL> max_age = request . session . get_expiry_age ( ) <EOL> expires_time = time . time ( ) + max_age <EOL> expires = cookie_date ( expires_time ) <EOL> request . session . save ( ) <EOL> response . set_cookie ( settings . SESSION_COOKIE_NAME , <EOL> request . session . session_key , max_age = max_age , <EOL> expires = expires , domain = settings . SESSION_COOKIE_DOMAIN , <EOL> path = settings . SESSION_COOKIE_PATH , <EOL> secure = settings . SESSION_COOKIE_SECURE or None , <EOL> httponly = settings . SESSION_COOKIE_HTTPONLY or None ) <EOL> return response </s>
