当前位置: 首页>>代码示例>>Python>>正文


Python http.ConditionalGetMiddleware类代码示例

本文整理汇总了Python中django.middleware.http.ConditionalGetMiddleware的典型用法代码示例。如果您正苦于以下问题:Python ConditionalGetMiddleware类的具体用法?Python ConditionalGetMiddleware怎么用?Python ConditionalGetMiddleware使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ConditionalGetMiddleware类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_if_modified_since_and_redirect

 def test_if_modified_since_and_redirect(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['Location'] = '/'
     self.resp.status_code = 301
     self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
     self.assertEqual(self.resp.status_code, 301)
开发者ID:troef,项目名称:django,代码行数:7,代码来源:tests.py

示例2: test_content_length_header_added

 def test_content_length_header_added(self):
     content_length = len(self.resp.content)
     # Already set by CommonMiddleware, remove it to check that
     # ConditionalGetMiddleware readds it.
     del self.resp['Content-Length']
     self.assertNotIn('Content-Length', self.resp)
     self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
     self.assertIn('Content-Length', self.resp)
     self.assertEqual(int(self.resp['Content-Length']), content_length)
开发者ID:adamkal,项目名称:django,代码行数:9,代码来源:tests.py

示例3: test_if_none_match_and_client_error

 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)
开发者ID:troef,项目名称:django,代码行数:5,代码来源:tests.py

示例4: test_if_none_match_and_redirect

 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:troef,项目名称:django,代码行数:6,代码来源:tests.py

示例5: test_if_none_match_and_different_etag

 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:troef,项目名称:django,代码行数:5,代码来源:tests.py

示例6: test_if_none_match_and_same_etag

 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:troef,项目名称:django,代码行数:4,代码来源:tests.py

示例7: test_no_if_none_match_and_etag

 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:troef,项目名称:django,代码行数:4,代码来源:tests.py

示例8: test_content_length_header_not_changed

 def test_content_length_header_not_changed(self):
     bad_content_length = len(self.resp.content) + 10
     self.resp['Content-Length'] = bad_content_length
     self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
     self.assertEqual(int(self.resp['Content-Length']), bad_content_length)
开发者ID:adamkal,项目名称:django,代码行数:5,代码来源:tests.py

示例9: ConditionalGetMiddlewareTest

class ConditionalGetMiddlewareTest(SimpleTestCase):

    def setUp(self):
        self.req = RequestFactory().get('/')
        self.resp = self.client.get(self.req.path_info)

    # Tests for the ETag header

    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'])

    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'])

    def test_no_etag_streaming_response(self):
        res = StreamingHttpResponse(['content'])
        self.assertFalse(ConditionalGetMiddleware().process_response(self.req, res).has_header('ETag'))

    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'))

    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'))

    def test_if_none_match_and_no_etag(self):
        self.req.META['HTTP_IF_NONE_MATCH'] = 'spam'
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 200)

    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)

    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)

    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)

    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)

    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

    def test_if_modified_since_and_no_last_modified(self):
        self.req.META['HTTP_IF_MODIFIED_SINCE'] = 'Sat, 12 Feb 2011 17:38:44 GMT'
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 200)

    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)

    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)

    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)

    def test_if_modified_since_and_last_modified_in_the_future(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:41:44 GMT'
        self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
        self.assertEqual(self.resp.status_code, 200)

    def test_if_modified_since_and_redirect(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['Location'] = '/'
#.........这里部分代码省略.........
开发者ID:troef,项目名称:django,代码行数:101,代码来源:tests.py

示例10: test_no_if_modified_since_and_last_modified

 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:troef,项目名称:django,代码行数:4,代码来源:tests.py

示例11: test_if_modified_since_and_last_modified_in_the_future

 def test_if_modified_since_and_last_modified_in_the_future(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:41:44 GMT'
     self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
     self.assertEqual(self.resp.status_code, 200)
开发者ID:troef,项目名称:django,代码行数:5,代码来源:tests.py

示例12: test_middleware_calculates_etag

 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:troef,项目名称:django,代码行数:5,代码来源:tests.py

示例13: test_if_modified_since_and_client_error

 def test_if_modified_since_and_client_error(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.status_code = 400
     self.resp = ConditionalGetMiddleware().process_response(self.req, self.resp)
     self.assertEqual(self.resp.status_code, 400)
开发者ID:troef,项目名称:django,代码行数:6,代码来源:tests.py

示例14: test_middleware_wont_overwrite_etag

 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:troef,项目名称:django,代码行数:5,代码来源:tests.py


注:本文中的django.middleware.http.ConditionalGetMiddleware类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。