U
    gëd_  ã                   @   sP   d dl mZ d dlmZ d dlmZ d dlmZmZ edƒZ	G dd„ deƒZ
dS )	é    )Úpatch_vary_headers)ÚMiddlewareMixin)Ú_lazy_re_compile)Ú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 st|jƒdk r|S | d¡r&|S t|dƒ |j dd¡}t |¡sL|S |j rht	|j
ƒ|_
|jd= n:t|jƒ}t|ƒt|jƒkrˆ|S ||_tt|jƒƒ|jd< | d¡}|rÈ| d¡rÈd	| |jd< d
|jd< |S )NéÈ   zContent-Encoding)zAccept-EncodingZHTTP_ACCEPT_ENCODINGÚ zContent-LengthÚETagú"zW/Úgzip)Z	streamingÚlenÚcontentÚ
has_headerr   ZMETAÚgetÚre_accepts_gzipÚsearchr   Zstreaming_contentÚheadersr   ÚstrÚ
startswith)ÚselfÚrequestÚresponseZaeZcompressed_contentÚetag© r   ú:/tmp/pip-unpacked-wheel-_p7c4jiu/django/middleware/gzip.pyÚprocess_response   s*    






zGZipMiddleware.process_responseN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   	   s   r   N)Zdjango.utils.cacher   Zdjango.utils.deprecationr   Zdjango.utils.regex_helperr   Zdjango.utils.textr   r   r   r   r   r   r   r   Ú<module>   s
   