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-EncodingZ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Zorignal_iteratorself }/home/ubuntu/experiments/live_experiments/Pythonexperiments/Otree/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)Z	streaminglencontent
has_headerr   ZMETAgetre_accepts_gzipsearchis_asyncZstreaming_contentr   r   headersr   str
startswith)r   requestresponseZaer   Z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)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    