
vÅÏ^X  ã               @   sV   d  d l  m Z m Z m Z d  d l m Z d  d l m Z Gd d „  d e ƒ Z d S)é    )Úcc_delim_reÚget_conditional_responseÚset_response_etag)ÚMiddlewareMixin)Úparse_http_date_safec               @   s.   e  Z d  Z d Z d d „  Z d d „  Z d S)ÚConditionalGetMiddlewarezé
    Handle conditional GET operations. If the response has an ETag or
    Last-Modified header and the request has If-None-Match or If-Modified-Since,
    replace the response with HttpNotModified. Add an ETag header if needed.
    c             C   s˜   | j  d k r | S|  j | ƒ r< | j d ƒ r< t | ƒ | j d ƒ } | j d ƒ } | oi t | ƒ } | sx | r” t | d | d | d | ƒS| S)NÚGETÚETagzLast-ModifiedÚetagÚlast_modifiedÚresponse)ÚmethodÚ
needs_etagÚ
has_headerr   Úgetr   r   )ÚselfÚrequestr   r
   r   © r   ú8/tmp/pip-build-8lau8j11/django/django/middleware/http.pyÚprocess_response   s    
z)ConditionalGetMiddleware.process_responsec             C   s2   t  j | j d d ƒ ƒ } t d d „  | Dƒ ƒ S)z:Return True if an ETag header should be added to response.zCache-ControlÚ c             s   s!   |  ] } | j  ƒ  d  k Vq d S)zno-storeN)Úlower)Ú.0Úheaderr   r   r   ú	<genexpr>)   s    z6ConditionalGetMiddleware.needs_etag.<locals>.<genexpr>)r   Úsplitr   Úall)r   r   Zcache_control_headersr   r   r   r   &   s    z#ConditionalGetMiddleware.needs_etagN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s   r   N)	Zdjango.utils.cacher   r   r   Zdjango.utils.deprecationr   Zdjango.utils.httpr   r   r   r   r   r   Ú<module>   s   