本文整理汇总了Python中twisted.web.test.test_web.DummyRequest.requestHeaders方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.requestHeaders方法的具体用法?Python DummyRequest.requestHeaders怎么用?Python DummyRequest.requestHeaders使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.test.test_web.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.requestHeaders方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_renderIProtocol
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import requestHeaders [as 别名]
def test_renderIProtocol(self):
"""
If the protocol returned by C{lookupProtocol} isn't a
C{WebSocketsProtocol}, L{WebSocketsResource} wraps it automatically
with L{WebSocketsProtocolWrapper}.
"""
def lookupProtocol(names, otherRequest):
return AccumulatingProtocol(), None
self.resource = WebSocketsResource(lookupProtocol)
request = DummyRequest("/")
request.requestHeaders = Headers()
transport = StringTransportWithDisconnection()
transport.protocol = Protocol()
request.transport = transport
request.headers.update({
"upgrade": "Websocket",
"connection": "Upgrade",
"sec-websocket-key": "secure",
"sec-websocket-version": "13"})
result = self.resource.render(request)
self.assertEqual(NOT_DONE_YET, result)
self.assertIsInstance(transport.protocol, WebSocketsProtocolWrapper)
self.assertIsInstance(transport.protocol.wrappedProtocol,
AccumulatingProtocol)
示例2: test_renderSecureRequest
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import requestHeaders [as 别名]
def test_renderSecureRequest(self):
"""
When the rendered request is over HTTPS, L{WebSocketsResource} wraps
the protocol of the C{TLSMemoryBIOProtocol} instance.
"""
request = DummyRequest("/")
request.requestHeaders = Headers()
transport = StringTransportWithDisconnection()
secureProtocol = TLSMemoryBIOProtocol(Factory(), Protocol())
transport.protocol = secureProtocol
request.transport = transport
request.headers.update({
"upgrade": "Websocket",
"connection": "Upgrade",
"sec-websocket-key": "secure",
"sec-websocket-version": "13"})
result = self.resource.render(request)
self.assertEqual(NOT_DONE_YET, result)
self.assertEqual(
{"connection": "Upgrade",
"upgrade": "WebSocket",
"sec-websocket-accept": "oYBv54i42V5dw6KnZqOFroecUTc="},
request.outgoingHeaders)
self.assertEqual([""], request.written)
self.assertEqual(101, request.responseCode)
self.assertIdentical(None, request.transport)
self.assertIsInstance(
transport.protocol.wrappedProtocol, WebSocketsProtocol)
self.assertIsInstance(
transport.protocol.wrappedProtocol._receiver,
SavingEchoReceiver)
示例3: test_renderProtocol
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import requestHeaders [as 别名]
def test_renderProtocol(self):
"""
If protocols are specified via the C{Sec-WebSocket-Protocol} header,
L{WebSocketsResource} passes them to its C{lookupProtocol} argument,
which can decide which protocol to return, and which is accepted.
"""
def lookupProtocol(names, otherRequest):
self.assertEqual(["foo", "bar"], names)
self.assertIdentical(request, otherRequest)
return self.echoProtocol, "bar"
self.resource = WebSocketsResource(lookupProtocol)
request = DummyRequest("/")
request.requestHeaders = Headers(
{"sec-websocket-protocol": ["foo", "bar"]})
transport = StringTransportWithDisconnection()
transport.protocol = Protocol()
request.transport = transport
request.headers.update({
"upgrade": "Websocket",
"connection": "Upgrade",
"sec-websocket-key": "secure",
"sec-websocket-version": "13"})
result = self.resource.render(request)
self.assertEqual(NOT_DONE_YET, result)
self.assertEqual(
{"connection": "Upgrade",
"upgrade": "WebSocket",
"sec-websocket-protocol": "bar",
"sec-websocket-accept": "oYBv54i42V5dw6KnZqOFroecUTc="},
request.outgoingHeaders)
self.assertEqual([""], request.written)
self.assertEqual(101, request.responseCode)
示例4: test_render
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import requestHeaders [as 别名]
def test_render(self):
"""
When rendering a request, L{WebSocketsResource} uses the
C{Sec-WebSocket-Key} header to generate a C{Sec-WebSocket-Accept}
value. It creates a L{WebSocketsProtocol} instance connected to the
protocol provided by the user factory.
"""
request = DummyRequest("/")
request.requestHeaders = Headers()
transport = StringTransportWithDisconnection()
transport.protocol = Protocol()
request.transport = transport
request.headers.update({
"upgrade": "Websocket",
"connection": "Upgrade",
"sec-websocket-key": "secure",
"sec-websocket-version": "13"})
result = self.resource.render(request)
self.assertEqual(NOT_DONE_YET, result)
self.assertEqual(
{"connection": "Upgrade",
"upgrade": "WebSocket",
"sec-websocket-accept": "oYBv54i42V5dw6KnZqOFroecUTc="},
request.outgoingHeaders)
self.assertEqual([""], request.written)
self.assertEqual(101, request.responseCode)
self.assertIdentical(None, request.transport)
self.assertIsInstance(transport.protocol._receiver,
SavingEchoReceiver)
示例5: request_generator
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import requestHeaders [as 别名]
def request_generator(url, method='GET', content=True, headers=True):
request = DummyRequest(url)
request.method = method
if content:
request.content = StringIO()
if headers:
request.requestHeaders = Headers()
return request
示例6: test_renderNoProtocol
# 需要导入模块: from twisted.web.test.test_web import DummyRequest [as 别名]
# 或者: from twisted.web.test.test_web.DummyRequest import requestHeaders [as 别名]
def test_renderNoProtocol(self):
"""
If the underlying factory doesn't return any protocol,
L{WebSocketsResource} returns a failed request with a C{502} code.
"""
request = DummyRequest("/")
request.requestHeaders = Headers()
request.transport = StringTransportWithDisconnection()
self.echoProtocol = None
request.headers.update({
"upgrade": "Websocket",
"connection": "Upgrade",
"sec-websocket-key": "secure",
"sec-websocket-version": "13"})
result = self.resource.render(request)
self.assertEqual("", result)
self.assertEqual({}, request.outgoingHeaders)
self.assertEqual([], request.written)
self.assertEqual(502, request.responseCode)