本文整理汇总了Python中falcon.request.Request.get_header方法的典型用法代码示例。如果您正苦于以下问题:Python Request.get_header方法的具体用法?Python Request.get_header怎么用?Python Request.get_header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类falcon.request.Request
的用法示例。
在下文中一共展示了Request.get_header方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestReqVars
# 需要导入模块: from falcon.request import Request [as 别名]
# 或者: from falcon.request.Request import get_header [as 别名]
class TestReqVars(helpers.TestSuite):
def prepare(self):
qs = '?marker=deadbeef&limit=10'
headers = {
'Content-Type': 'text/plain',
'Content-Length': '4829'
}
self.req = Request(helpers.create_environ(script='/test',
path='/hello',
query_string=qs,
headers=headers))
def test_reconstruct_url(self):
req = self.req
scheme = req.protocol
host = req.get_header('host')
app = req.app
path = req.path
query_string = req.query_string
expected_url = 'http://falconer/test/hello?marker=deadbeef&limit=10'
actual_url = ''.join([scheme, '://', host, app, path, query_string])
self.assertEquals(actual_url, expected_url)
def test_method(self):
self.assertEquals(self.req.method, 'GET')
self.req = Request(helpers.create_environ(path='', method='HEAD'))
self.assertEquals(self.req.method, 'HEAD')
def test_empty_path(self):
self.req = Request(helpers.create_environ(path=''))
self.assertEquals(self.req.path, '/')
def test_content_type(self):
self.assertEquals(self.req.get_header('content-type'), 'text/plain')
def test_content_length(self):
self.assertEquals(self.req.get_header('content-length'), '4829')
示例2: TestReqVars
# 需要导入模块: from falcon.request import Request [as 别名]
# 或者: from falcon.request.Request import get_header [as 别名]
class TestReqVars(testing.TestBase):
def before(self):
self.qs = 'marker=deadbeef&limit=10'
self.headers = {
'Content-Type': 'text/plain',
'Content-Length': '4829',
'Authorization': ''
}
self.app = '/test'
self.path = '/hello'
self.relative_uri = self.path + '?' + self.qs
self.req = Request(testing.create_environ(
app=self.app,
port=8080,
path='/hello',
query_string=self.qs,
headers=self.headers))
self.req_noqs = Request(testing.create_environ(
app=self.app,
path='/hello',
headers=self.headers))
def test_missing_qs(self):
env = testing.create_environ()
if 'QUERY_STRING' in env:
del env['QUERY_STRING']
# Should not cause an exception when Request is instantiated
Request(env)
def test_empty(self):
self.assertIs(self.req.auth, None)
def test_host(self):
self.assertEqual(self.req.host, testing.DEFAULT_HOST)
def test_subdomain(self):
req = Request(testing.create_environ(
host='com',
path='/hello',
headers=self.headers))
self.assertIs(req.subdomain, None)
req = Request(testing.create_environ(
host='example.com',
path='/hello',
headers=self.headers))
self.assertEqual(req.subdomain, 'example')
req = Request(testing.create_environ(
host='highwire.example.com',
path='/hello',
headers=self.headers))
self.assertEqual(req.subdomain, 'highwire')
req = Request(testing.create_environ(
host='lb01.dfw01.example.com',
port=8080,
path='/hello',
headers=self.headers))
self.assertEqual(req.subdomain, 'lb01')
# NOTE(kgriffs): Behavior for IP addresses is undefined,
# so just make sure it doesn't blow up.
req = Request(testing.create_environ(
host='127.0.0.1',
path='/hello',
headers=self.headers))
self.assertEqual(type(req.subdomain), str)
# NOTE(kgriffs): Test fallback to SERVER_NAME by using
# HTTP 1.0, which will cause .create_environ to not set
# HTTP_HOST.
req = Request(testing.create_environ(
protocol='HTTP/1.0',
host='example.com',
path='/hello',
headers=self.headers))
self.assertEqual(req.subdomain, 'example')
def test_reconstruct_url(self):
req = self.req
scheme = req.protocol
host = req.get_header('host')
app = req.app
path = req.path
query_string = req.query_string
expected_uri = ''.join([scheme, '://', host, app, path,
'?', query_string])
self.assertEqual(expected_uri, req.uri)
@testtools.skipUnless(six.PY3, 'Test only applies to Python 3')
#.........这里部分代码省略.........
示例3: TestReqVars
# 需要导入模块: from falcon.request import Request [as 别名]
# 或者: from falcon.request.Request import get_header [as 别名]
class TestReqVars(testing.TestSuite):
def prepare(self):
qs = '?marker=deadbeef&limit=10'
headers = {
'Content-Type': 'text/plain',
'Content-Length': '4829',
}
self.url = 'http://falconer/test/hello?marker=deadbeef&limit=10'
self.req = Request(testing.create_environ(script='/test',
path='/hello',
query_string=qs,
headers=headers))
def test_reconstruct_url(self):
req = self.req
scheme = req.protocol
host = req.get_header('host')
app = req.app
path = req.path
query_string = req.query_string
actual_url = ''.join([scheme, '://', host, app, path, query_string])
self.assertEquals(self.url, actual_url)
def test_url(self):
self.assertEquals(self.url, self.req.url)
def test_range(self):
headers = {'Range': '10-'}
req = Request(testing.create_environ(headers=headers))
self.assertEquals((10, -1), req.range)
headers = {'Range': '10-20'}
req = Request(testing.create_environ(headers=headers))
self.assertEquals((10, 20), req.range)
headers = {'Range': '-10240'}
req = Request(testing.create_environ(headers=headers))
self.assertEquals((-10240, -1), req.range)
headers = {'Range': '10240'}
req = Request(testing.create_environ(headers=headers))
self.assertEqual(None, req.range)
headers = {'Range': ''}
req = Request(testing.create_environ(headers=headers))
self.assertEqual(None, req.range)
headers = {'Range': '-'}
req = Request(testing.create_environ(headers=headers))
self.assertEqual(None, req.range)
headers = {'Range': '--'}
req = Request(testing.create_environ(headers=headers))
self.assertEqual(None, req.range)
headers = {'Range': '-3-'}
req = Request(testing.create_environ(headers=headers))
self.assertEqual(None, req.range)
headers = {'Range': '-3-4'}
req = Request(testing.create_environ(headers=headers))
self.assertEqual(None, req.range)
headers = {'Range': '3-3-4'}
req = Request(testing.create_environ(headers=headers))
self.assertEqual(None, req.range)
headers = {'Range': '3-3-'}
req = Request(testing.create_environ(headers=headers))
self.assertEqual(None, req.range)
headers = {'Range': None}
req = Request(testing.create_environ(headers=headers))
self.assertEqual(None, req.range)
def test_attribute_headers(self):
date = testing.httpnow()
hash = 'fa0d1a60ef6616bb28038515c8ea4cb2'
auth = 'HMAC_SHA1 c590afa9bb59191ffab30f223791e82d3fd3e3af'
agent = 'curl/7.24.0 (x86_64-apple-darwin12.0)'
self._test_attribute_header('Accept', 'x-falcon', 'accept')
self._test_attribute_header('Authorization', auth, 'auth')
self._test_attribute_header('Content-Length', '4829', 'content_length')
self._test_attribute_header('Content-Type', 'text/plain',
'content_type')
self._test_attribute_header('Expect', '100-continue', 'expect')
self._test_attribute_header('Date', date, 'date')
self._test_attribute_header('If-Match', hash, 'if_match')
self._test_attribute_header('If-Modified-Since', date,
'if_modified_since')
self._test_attribute_header('If-None-Match', hash, 'if_none_match')
#.........这里部分代码省略.........
示例4: TestReqVars
# 需要导入模块: from falcon.request import Request [as 别名]
# 或者: from falcon.request.Request import get_header [as 别名]
class TestReqVars(testing.TestBase):
def before(self):
self.qs = 'marker=deadbeef&limit=10'
self.headers = {
'Host': 'falcon.example.com',
'Content-Type': 'text/plain',
'Content-Length': '4829',
'Authorization': ''
}
self.app = '/test'
self.path = '/hello'
self.relative_uri = self.path + '?' + self.qs
self.uri = 'http://falcon.example.com' + self.app + self.relative_uri
self.uri_noqs = 'http://falcon.example.com' + self.app + self.path
self.req = Request(testing.create_environ(
app=self.app,
path='/hello',
query_string=self.qs,
headers=self.headers))
self.req_noqs = Request(testing.create_environ(
app=self.app,
path='/hello',
headers=self.headers))
def test_missing_qs(self):
env = testing.create_environ()
if 'QUERY_STRING' in env:
del env['QUERY_STRING']
# Should not cause an exception when Request is instantiated
Request(env)
def test_empty(self):
self.assertIs(self.req.auth, None)
def test_reconstruct_url(self):
req = self.req
scheme = req.protocol
host = req.get_header('host')
app = req.app
path = req.path
query_string = req.query_string
actual_url = ''.join([scheme, '://', host, app, path,
'?', query_string])
self.assertEquals(actual_url, self.uri)
def test_uri(self):
self.assertEquals(self.req.url, self.uri)
self.assertEquals(self.req.uri, self.uri)
self.assertEquals(self.req_noqs.uri, self.uri_noqs)
def test_relative_uri(self):
self.assertEqual(self.req.relative_uri, self.app + self.relative_uri)
self.assertEqual(
self.req_noqs.relative_uri, self.app + self.path)
req_noapp = Request(testing.create_environ(
path='/hello',
query_string=self.qs,
headers=self.headers))
self.assertEqual(req_noapp.relative_uri, self.relative_uri)
req_noapp = Request(testing.create_environ(
path='/hello/',
query_string=self.qs,
headers=self.headers))
self.assertEqual(req_noapp.relative_uri, self.relative_uri)
def test_accept_xml(self):
headers = {'Accept': 'application/xml'}
req = Request(testing.create_environ(headers=headers))
self.assertTrue(req.client_accepts_xml)
headers = {'Accept': '*/*'}
req = Request(testing.create_environ(headers=headers))
self.assertTrue(req.client_accepts_xml)
headers = {'Accept': 'application/json'}
req = Request(testing.create_environ(headers=headers))
self.assertFalse(req.client_accepts_xml)
headers = {'Accept': 'application/xm'}
req = Request(testing.create_environ(headers=headers))
self.assertFalse(req.client_accepts_xml)
def test_range(self):
headers = {'Range': '10-'}
req = Request(testing.create_environ(headers=headers))
self.assertEquals(req.range, (10, -1))
#.........这里部分代码省略.........
示例5: setup_method
# 需要导入模块: from falcon.request import Request [as 别名]
# 或者: from falcon.request.Request import get_header [as 别名]
class TestRequestAttributes:
def setup_method(self, method):
self.qs = 'marker=deadbeef&limit=10'
self.headers = {
'Content-Type': 'text/plain',
'Content-Length': '4829',
'Authorization': ''
}
self.app = '/test'
self.path = '/hello'
self.relative_uri = self.path + '?' + self.qs
self.req = Request(testing.create_environ(
app=self.app,
port=8080,
path='/hello',
query_string=self.qs,
headers=self.headers))
self.req_noqs = Request(testing.create_environ(
app=self.app,
path='/hello',
headers=self.headers))
def test_missing_qs(self):
env = testing.create_environ()
if 'QUERY_STRING' in env:
del env['QUERY_STRING']
# Should not cause an exception when Request is instantiated
Request(env)
def test_empty(self):
assert self.req.auth is None
def test_host(self):
assert self.req.host == testing.DEFAULT_HOST
def test_subdomain(self):
req = Request(testing.create_environ(
host='com',
path='/hello',
headers=self.headers))
assert req.subdomain is None
req = Request(testing.create_environ(
host='example.com',
path='/hello',
headers=self.headers))
assert req.subdomain == 'example'
req = Request(testing.create_environ(
host='highwire.example.com',
path='/hello',
headers=self.headers))
assert req.subdomain == 'highwire'
req = Request(testing.create_environ(
host='lb01.dfw01.example.com',
port=8080,
path='/hello',
headers=self.headers))
assert req.subdomain == 'lb01'
# NOTE(kgriffs): Behavior for IP addresses is undefined,
# so just make sure it doesn't blow up.
req = Request(testing.create_environ(
host='127.0.0.1',
path='/hello',
headers=self.headers))
assert type(req.subdomain) == str
# NOTE(kgriffs): Test fallback to SERVER_NAME by using
# HTTP 1.0, which will cause .create_environ to not set
# HTTP_HOST.
req = Request(testing.create_environ(
protocol='HTTP/1.0',
host='example.com',
path='/hello',
headers=self.headers))
assert req.subdomain == 'example'
def test_reconstruct_url(self):
req = self.req
scheme = req.scheme
host = req.get_header('host')
app = req.app
path = req.path
query_string = req.query_string
expected_prefix = ''.join([scheme, '://', host, app])
expected_uri = ''.join([expected_prefix, path, '?', query_string])
assert req.uri == expected_uri
assert req.prefix == expected_prefix
assert req.prefix == expected_prefix # Check cached value
#.........这里部分代码省略.........
示例6: TestReqVars
# 需要导入模块: from falcon.request import Request [as 别名]
# 或者: from falcon.request.Request import get_header [as 别名]
class TestReqVars(object):
def setup_method(self, method):
self.qs = 'marker=deadbeef&limit=10'
self.headers = {
'Content-Type': 'text/plain',
'Content-Length': '4829',
'Authorization': ''
}
self.app = '/test'
self.path = '/hello'
self.relative_uri = self.path + '?' + self.qs
self.req = Request(testing.create_environ(
app=self.app,
port=8080,
path='/hello',
query_string=self.qs,
headers=self.headers))
self.req_noqs = Request(testing.create_environ(
app=self.app,
path='/hello',
headers=self.headers))
def test_missing_qs(self):
env = testing.create_environ()
if 'QUERY_STRING' in env:
del env['QUERY_STRING']
# Should not cause an exception when Request is instantiated
Request(env)
def test_empty(self):
assert self.req.auth is None
def test_host(self):
assert self.req.host == testing.DEFAULT_HOST
def test_subdomain(self):
req = Request(testing.create_environ(
host='com',
path='/hello',
headers=self.headers))
assert req.subdomain is None
req = Request(testing.create_environ(
host='example.com',
path='/hello',
headers=self.headers))
assert req.subdomain == 'example'
req = Request(testing.create_environ(
host='highwire.example.com',
path='/hello',
headers=self.headers))
assert req.subdomain == 'highwire'
req = Request(testing.create_environ(
host='lb01.dfw01.example.com',
port=8080,
path='/hello',
headers=self.headers))
assert req.subdomain == 'lb01'
# NOTE(kgriffs): Behavior for IP addresses is undefined,
# so just make sure it doesn't blow up.
req = Request(testing.create_environ(
host='127.0.0.1',
path='/hello',
headers=self.headers))
assert type(req.subdomain) == str
# NOTE(kgriffs): Test fallback to SERVER_NAME by using
# HTTP 1.0, which will cause .create_environ to not set
# HTTP_HOST.
req = Request(testing.create_environ(
protocol='HTTP/1.0',
host='example.com',
path='/hello',
headers=self.headers))
assert req.subdomain == 'example'
def test_reconstruct_url(self):
req = self.req
scheme = req.protocol
host = req.get_header('host')
app = req.app
path = req.path
query_string = req.query_string
expected_uri = ''.join([scheme, '://', host, app, path,
'?', query_string])
assert expected_uri == req.uri
@pytest.mark.skipif(not six.PY3, reason='Test only applies to Python 3')
#.........这里部分代码省略.........