<s> from django . conf import settings <EOL> from django . utils . six . moves import http_client <EOL> from csp . utils import build_policy <EOL> class CSPMiddleware ( object ) : <EOL> """<STR_LIT>""" <EOL> def process_response ( self , request , response ) : <EOL> if getattr ( response , '<STR_LIT>' , False ) : <EOL> return response <EOL> prefixes = getattr ( settings , '<STR_LIT>' , ( ) ) <EOL> if request . path_info . startswith ( prefixes ) : <EOL> return response <EOL> status_code = response . status_code <EOL> if status_code == http_client . INTERNAL_SERVER_ERROR and settings . DEBUG : <EOL> return response <EOL> header = '<STR_LIT>' <EOL> if getattr ( settings , '<STR_LIT>' , False ) : <EOL> header += '<STR_LIT>' <EOL> if header in response : <EOL> return response <EOL> config = getattr ( response , '<STR_LIT>' , None ) <EOL> update = getattr ( response , '<STR_LIT>' , None ) <EOL> replace = getattr ( response , '<STR_LIT>' , None ) <EOL> response [ header ] = build_policy ( config = config , update = update , <EOL> replace = replace ) <EOL> return response </s>
