o
    þÞh�  ã                   @   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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.
    éd   c                    s  |j st|jƒdk r|S | d¡r|S t|dƒ |j dd¡}t |¡s&|S |j rI|j	r;|j
‰ ‡ ‡fdd„}|ƒ |_
n	t|j
ˆjd�|_
|jd	= n t|jˆjd�}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-EncodingÚHTTP_ACCEPT_ENCODINGÚ c                    s*   �ˆ 2 z3 d H W } t | ˆjd�V  q6 d S )N©Úmax_random_bytes)r   r   )Úchunk©Úorignal_iteratorÚself© úV/var/www/html/premium_crap/venv/lib/python3.10/site-packages/django/middleware/gzip.pyÚgzip_wrapper'   s   €
þÿz5GZipMiddleware.process_response.<locals>.gzip_wrapperr   zContent-LengthÚETagú"zW/Úgzip)Ú	streamingÚlenÚcontentÚ
has_headerr   ÚMETAÚgetÚre_accepts_gzipÚsearchÚis_asyncÚstreaming_contentr   r   Úheadersr   ÚstrÚ
startswith)r   ÚrequestÚresponseÚaer   Úcompressed_contentÚetagr   r   r   Úprocess_response   s>   



þ
þ

zGZipMiddleware.process_responseN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r*   r   r   r   r   r   	   s    r   N)Údjango.utils.cacher   Údjango.utils.deprecationr   Údjango.utils.regex_helperr   Údjango.utils.textr   r   r   r   r   r   r   r   Ú<module>   s    