<s> import re <EOL> from django . utils . text import compress_string <EOL> from django . utils . cache import patch_vary_headers <EOL> re_accepts_gzip = re . compile ( r'<STR_LIT>' ) <EOL> class GZipMiddleware ( object ) : <EOL> """<STR_LIT>""" <EOL> def process_response ( self , request , response ) : <EOL> if response . status_code != <NUM_LIT:200> or len ( response . content ) < <NUM_LIT:200> : <EOL> return response <EOL> patch_vary_headers ( response , ( '<STR_LIT>' , ) ) <EOL> if response . has_header ( '<STR_LIT>' ) : <EOL> return response <EOL> if "<STR_LIT>" in request . META . get ( '<STR_LIT>' , '<STR_LIT>' ) . lower ( ) : <EOL> ctype = response . get ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) . lower ( ) <EOL> if not ctype . startswith ( "<STR_LIT>" ) or "<STR_LIT>" in ctype : <EOL> return response <EOL> ae = request . META . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not re_accepts_gzip . search ( ae ) : <EOL> return response <EOL> response . content = compress_string ( response . content ) <EOL> response [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> response [ '<STR_LIT>' ] = str ( len ( response . content ) ) <EOL> return response </s>
