
    g                     ^    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e      Z
y)	    )patch_vary_headers)MiddlewareMixin)_lazy_re_compile)compress_sequencecompress_stringz\bgzip\bc                       e Zd ZdZdZd Zy)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                 F    |j                   st        |j                        dk  r|S |j                  d      r|S t	        |d       |j
                  j                  dd      }t        j                  |      s|S |j                   r_|j                  r|j                   fd} |       |_
        n&t        |j                   j                        |_
        |j                  d= nvt        |j                   j                        }t        |      t        |j                        k\  r|S ||_        t        t        |j                              |j                  d<   |j                  d	      }|r#|j!                  d
      rd|z   |j                  d	<   d|j                  d<   |S )N   zContent-Encoding)zAccept-EncodingHTTP_ACCEPT_ENCODING c                 `   K   2 3 d {   } t        | j                         $7 6 y w)Nmax_random_bytes)r   r   )chunkorignal_iteratorselfs    n/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/middleware/gzip.pygzip_wrapperz5GZipMiddleware.process_response.<locals>.gzip_wrapper'   s3     '7 e-!-1-B-B '7s   .,*,.,.r   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   s   `      @r   process_responsezGZipMiddleware.process_response   s   !!c(*:*:&;c&AO 12O8%9:\\4b9%%b)O   $,#=#=  .:^*->..%)%:%:.*   !12 "1  !%!6!6" %&#h.>.>*??1H14S9I9I5J1KH-.
 ||F#DOOC('+d{HV$/5+,    N)__name__
__module____qualname____doc__r   r,    r-   r   r	   r	   	   s     8r-   r	   N)django.utils.cacher   django.utils.deprecationr   django.utils.regex_helperr   django.utils.textr   r   r    r	   r2   r-   r   <module>r7      s)    1 4 6 @";/A_ Ar-   