當前位置: 首頁>>代碼示例>>Python>>正文


Python http.ConditionalGetMiddleware方法代碼示例

本文整理匯總了Python中django.middleware.http.ConditionalGetMiddleware方法的典型用法代碼示例。如果您正苦於以下問題:Python http.ConditionalGetMiddleware方法的具體用法?Python http.ConditionalGetMiddleware怎麽用?Python http.ConditionalGetMiddleware使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.middleware.http的用法示例。


在下文中一共展示了http.ConditionalGetMiddleware方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_not_modified_headers

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_not_modified_headers(self):
        """
        The 304 Not Modified response should include only the headers required
        by section 4.1 of RFC 7232, Last-Modified, and the cookies.
        """
        self.req.META['HTTP_IF_NONE_MATCH'] = self.resp['ETag'] = '"spam"'
        self.resp['Date'] = 'Sat, 12 Feb 2011 17:35:44 GMT'
        self.resp['Last-Modified'] = 'Sat, 12 Feb 2011 17:35:44 GMT'
        self.resp['Expires'] = 'Sun, 13 Feb 2011 17:35:44 GMT'
        self.resp['Vary'] = 'Cookie'
        self.resp['Cache-Control'] = 'public'
        self.resp['Content-Location'] = '/alt'
        self.resp['Content-Language'] = 'en'  # shouldn't be preserved
        self.resp.set_cookie('key', 'value')

        new_response = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(new_response.status_code, 304)
        for header in ('Cache-Control', 'Content-Location', 'Date', 'ETag', 'Expires', 'Last-Modified', 'Vary'):
            self.assertEqual(new_response[header], self.resp[header])
        self.assertEqual(new_response.cookies, self.resp.cookies)
        self.assertNotIn('Content-Language', new_response) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:23,代碼來源:tests.py

示例2: test_etag_match

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_etag_match(self):
        """
        GZipMiddleware allows 304 Not Modified responses.
        """
        request = self.rf.get('/', HTTP_ACCEPT_ENCODING='gzip, deflate')
        response = GZipMiddleware().process_response(
            request,
            ConditionalGetMiddleware().process_response(request, HttpResponse(self.compressible_string))
        )
        gzip_etag = response['ETag']
        next_request = self.rf.get('/', HTTP_ACCEPT_ENCODING='gzip, deflate', HTTP_IF_NONE_MATCH=gzip_etag)
        next_response = ConditionalGetMiddleware().process_response(
            next_request,
            HttpResponse(self.compressible_string)
        )
        self.assertEqual(next_response.status_code, 304) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:tests.py

示例3: test_middleware_calculates_etag

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_middleware_calculates_etag(self):
        self.assertNotIn('ETag', self.resp)
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 200)
        self.assertNotEqual('', self.resp['ETag']) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:tests.py

示例4: test_middleware_wont_overwrite_etag

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_middleware_wont_overwrite_etag(self):
        self.resp['ETag'] = 'eggs'
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 200)
        self.assertEqual('eggs', self.resp['ETag']) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:tests.py

示例5: test_no_etag_streaming_response

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_no_etag_streaming_response(self):
        res = StreamingHttpResponse(['content'])
        self.assertFalse(ConditionalGetMiddleware().process_response(self.req, res).has_header('ETag')) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:5,代碼來源:tests.py

示例6: test_no_etag_no_store_cache

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_no_etag_no_store_cache(self):
        self.resp['Cache-Control'] = 'No-Cache, No-Store, Max-age=0'
        self.assertFalse(ConditionalGetMiddleware().process_response(self.req, self.resp).has_header('ETag')) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:5,代碼來源:tests.py

示例7: test_etag_extended_cache_control

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_etag_extended_cache_control(self):
        self.resp['Cache-Control'] = 'my-directive="my-no-store"'
        self.assertTrue(ConditionalGetMiddleware().process_response(self.req, self.resp).has_header('ETag')) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:5,代碼來源:tests.py

示例8: test_no_if_none_match_and_etag

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_no_if_none_match_and_etag(self):
        self.resp['ETag'] = 'eggs'
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 200) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:tests.py

示例9: test_if_none_match_and_same_etag

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_if_none_match_and_same_etag(self):
        self.req.META['HTTP_IF_NONE_MATCH'] = self.resp['ETag'] = '"spam"'
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 304) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:tests.py

示例10: test_if_none_match_and_different_etag

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_if_none_match_and_different_etag(self):
        self.req.META['HTTP_IF_NONE_MATCH'] = 'spam'
        self.resp['ETag'] = 'eggs'
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 200) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:tests.py

示例11: test_if_none_match_and_redirect

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_if_none_match_and_redirect(self):
        self.req.META['HTTP_IF_NONE_MATCH'] = self.resp['ETag'] = 'spam'
        self.resp['Location'] = '/'
        self.resp.status_code = 301
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 301) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:8,代碼來源:tests.py

示例12: test_if_none_match_and_client_error

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_if_none_match_and_client_error(self):
        self.req.META['HTTP_IF_NONE_MATCH'] = self.resp['ETag'] = 'spam'
        self.resp.status_code = 400
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 400)

    # Tests for the Last-Modified header 
開發者ID:nesdis,項目名稱:djongo,代碼行數:9,代碼來源:tests.py

示例13: test_no_if_modified_since_and_last_modified

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_no_if_modified_since_and_last_modified(self):
        self.resp['Last-Modified'] = 'Sat, 12 Feb 2011 17:38:44 GMT'
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 200) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:tests.py

示例14: test_if_modified_since_and_same_last_modified

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_if_modified_since_and_same_last_modified(self):
        self.req.META['HTTP_IF_MODIFIED_SINCE'] = 'Sat, 12 Feb 2011 17:38:44 GMT'
        self.resp['Last-Modified'] = 'Sat, 12 Feb 2011 17:38:44 GMT'
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 304) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:tests.py

示例15: test_if_modified_since_and_last_modified_in_the_past

# 需要導入模塊: from django.middleware import http [as 別名]
# 或者: from django.middleware.http import ConditionalGetMiddleware [as 別名]
def test_if_modified_since_and_last_modified_in_the_past(self):
        self.req.META['HTTP_IF_MODIFIED_SINCE'] = 'Sat, 12 Feb 2011 17:38:44 GMT'
        self.resp['Last-Modified'] = 'Sat, 12 Feb 2011 17:35:44 GMT'
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 304) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:7,代碼來源:tests.py


注:本文中的django.middleware.http.ConditionalGetMiddleware方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。