示例#1
0
    def process_response(self, request, response):
        """
        Calculate the ETag, if needed.

        When the status code of the response is 404, it may redirect to a path
        with an appended slash if should_redirect_with_slash() returns True.
        """
        # If the given URL is "Not Found", then check if we should redirect to
        # a path with a slash appended.
        if response.status_code == 404:
            if self.should_redirect_with_slash(request):
                return self.response_redirect_class(self.get_full_path_with_slash(request))

        if settings.USE_ETAGS:
            if not response.has_header('ETag'):
                set_response_etag(response)

            if response.has_header('ETag'):
                return get_conditional_response(
                    request,
                    etag=unquote_etag(response['ETag']),
                    response=response,
                )

        return response
示例#2
0
 def process_response(self, request, response):
     if (not response.streaming
             and not response.has_header('Content-Length')):
         response['Content-Length'] = str(  # pragma: no cover
             len(response.content))
     etag = response.get('ETag')
     if etag:
         return get_conditional_response(
             request,
             etag=unquote_etag(etag),
             response=response,
         )
     return response
示例#3
0
    def process_response(self, request, response):
        response['Date'] = http_date()
        if not response.streaming and not response.has_header('Content-Length'):
            response['Content-Length'] = str(len(response.content))

        etag = response.get('ETag')
        last_modified = response.get('Last-Modified')
        if last_modified:
            last_modified = parse_http_date_safe(last_modified)

        if etag or last_modified:
            return get_conditional_response(
                request,
                etag=unquote_etag(etag),
                last_modified=last_modified,
                response=response,
            )

        return response
示例#4
0
文件: http.py 项目: neogoku/nfv_api
    def process_response(self, request, response):
        response['Date'] = http_date()
        if not response.streaming and not response.has_header('Content-Length'):
            response['Content-Length'] = str(len(response.content))

        etag = response.get('ETag')
        last_modified = response.get('Last-Modified')
        if last_modified:
            last_modified = parse_http_date_safe(last_modified)

        if etag or last_modified:
            return get_conditional_response(
                request,
                etag=unquote_etag(etag),
                last_modified=last_modified,
                response=response,
            )

        return response
示例#5
0
 def test_quoting(self):
     original_etag = r'e\t"ag'
     quoted_etag = http.quote_etag(original_etag)
     self.assertEqual(quoted_etag, r'"e\\t\"ag"')
     self.assertEqual(http.unquote_etag(quoted_etag), original_etag)
示例#6
0
 def test_quoting(self):
     original_etag = r'e\t"ag'
     quoted_etag = http.quote_etag(original_etag)
     self.assertEqual(quoted_etag, r'"e\\t\"ag"')
     self.assertEqual(http.unquote_etag(quoted_etag), original_etag)
示例#7
0
from django.utils.cache import get_conditional_response
示例#8
0
import logging