
v^                 @   sk   d  d l  Z  d  d l m Z d  d l m Z d  d l m Z m Z e  j d  Z	 Gd d   d e  Z
 d S)    N)patch_vary_headers)MiddlewareMixin)compress_sequencecompress_stringz\bgzip\bc               @   s"   e  Z d  Z d Z d d   Z d S)GZipMiddlewarez
    Compress content if the browser allows gzip compression.
    Set the Vary header accordingly, so that caches will base their storage
    on the Accept-Encoding header.
    c             C   s   | j  r# t | j  d k  r# | S| j d  r6 | St | d  | j j d d  } t j |  sk | S| j  r t	 | j
  | _
 | d =nP t | j  } t |  t | j  k r | S| | _ t t | j   | d <| j d  } | r| j d  rd	 | | d <d
 | d <| S)N   zContent-EncodingAccept-EncodingZHTTP_ACCEPT_ENCODING zContent-LengthETag"zW/gzip)r   )Z	streaminglencontent
has_headerr   ZMETAgetre_accepts_gzipsearchr   Zstreaming_contentr   str
startswith)selfrequestresponseZaeZcompressed_contentetag r   8/tmp/pip-build-8lau8j11/django/django/middleware/gzip.pyprocess_response   s*    	
	
zGZipMiddleware.process_responseN)__name__
__module____qualname____doc__r   r   r   r   r   r   
   s   r   )reZdjango.utils.cacher   Zdjango.utils.deprecationr   Zdjango.utils.textr   r   compiler   r   r   r   r   r   <module>   s
   