本文整理汇总了Python中cyclone.web.RequestHandler.add_header方法的典型用法代码示例。如果您正苦于以下问题:Python RequestHandler.add_header方法的具体用法?Python RequestHandler.add_header怎么用?Python RequestHandler.add_header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cyclone.web.RequestHandler
的用法示例。
在下文中一共展示了RequestHandler.add_header方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: RequestHandlerTest
# 需要导入模块: from cyclone.web import RequestHandler [as 别名]
# 或者: from cyclone.web.RequestHandler import add_header [as 别名]
class RequestHandlerTest(unittest.TestCase):
def assertHasAttr(self, obj, attr_name):
assert hasattr(obj, attr_name)
def setUp(self):
self.app = Application(some_setting="foo")
self.request = Mock()
self.rh = RequestHandler(self.app, self.request)
def test_init(self):
self.assertHasAttr(self.rh, "application")
self.assertHasAttr(self.rh, "request")
self.assertHasAttr(self.rh, "path_args")
self.assertHasAttr(self.rh, "path_kwargs")
self.assertHasAttr(self.rh, "ui")
def test_settings(self):
self.assertEqual(self.rh.settings, {"some_setting": "foo"})
def test_default(self):
self.assertRaises(HTTPError, self.rh.default)
def test_prepare(self):
self.assertEqual(self.rh.prepare(), None)
def test_on_finish(self):
self.assertEqual(self.rh.on_finish(), None)
def test_on_connection_close(self):
self.assertEqual(self.rh.on_connection_close(), None)
def test_clear(self):
self.request.headers = {
"Connection": "Keep-Alive"
}
self.request.supports_http_1_1.return_value = False
self.rh.clear()
self.assertEqual(
set(self.rh._headers.keys()),
{"Server", "Content-Type", "Date", "Connection"},
)
self.assertEqual(self.rh._list_headers, [])
def test_set_status(self):
self.rh.set_status(200)
self.assertEqual(self.rh._status_code, 200)
def test_set_status_with_reason(self):
self.rh.set_status(200, "reason")
self.assertEqual(self.rh._status_code, 200)
self.assertEqual(self.rh._reason, "reason")
def test_set_status_with_invalid_code(self):
self.assertRaises(ValueError, self.rh.set_status, 9999)
def test_get_status(self):
self.rh.set_status(200)
self.assertEqual(self.rh.get_status(), 200)
def test_add_header(self):
self.rh.add_header("X-Header", "something")
self.assertEqual(
self.rh._list_headers,
[("X-Header", "something")]
)
self.rh.add_header("X-Header", "something")
self.assertEqual(
self.rh._list_headers,
[("X-Header", "something"), ("X-Header", "something")]
)
def test_clear_header(self):
self.rh.set_header("X-Header", "something")
self.assertTrue("X-Header" in self.rh._headers)
self.rh.clear_header("X-Header")
self.assertTrue("X-Header" not in self.rh._headers)
def test_convert_header_value(self):
value = self.rh._convert_header_value("Value")
self.assertEqual(value, "Value")
def test_convert_unicode_header_value(self):
value = self.rh._convert_header_value(u"Value")
self.assertEqual(value, "Value")
self.assertTrue(type(value) != unicode_type)
def test_convert_unicode_datetime_header_value(self):
now = datetime(2014, 4, 4)
result = self.rh._convert_header_value(now)
self.assertEqual(
result,
"Fri, 04 Apr 2014 00:00:00 GMT"
)
def test_convert_invalid_value(self):
class Nothing:
pass
self.assertRaises(TypeError, self.rh._convert_header_value, Nothing())
#.........这里部分代码省略.........