Python: supporting ASGI legacy protocol.
Introducing manual protocol selection for 'universal' apps and frameworks.
This commit is contained in:
13
test/python/legacy/asgi.py
Normal file
13
test/python/legacy/asgi.py
Normal file
@@ -0,0 +1,13 @@
|
||||
def application(scope):
|
||||
assert scope['type'] == 'http'
|
||||
|
||||
return app_http
|
||||
|
||||
async def app_http(receive, send):
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
]
|
||||
})
|
||||
17
test/python/legacy_force/asgi.py
Normal file
17
test/python/legacy_force/asgi.py
Normal file
@@ -0,0 +1,17 @@
|
||||
def application(scope, receive=None, send=None):
|
||||
assert scope['type'] == 'http'
|
||||
|
||||
if receive == None and send == None:
|
||||
return app_http
|
||||
|
||||
else:
|
||||
return app_http(receive, send)
|
||||
|
||||
async def app_http(receive, send):
|
||||
await send({
|
||||
'type': 'http.response.start',
|
||||
'status': 200,
|
||||
'headers': [
|
||||
(b'content-length', b'0'),
|
||||
]
|
||||
})
|
||||
@@ -418,3 +418,29 @@ Connection: close
|
||||
sock.close()
|
||||
|
||||
assert len(socks) == len(threads), 'threads differs'
|
||||
|
||||
def test_asgi_application_legacy(self):
|
||||
self.load('legacy')
|
||||
|
||||
resp = self.get(
|
||||
headers={
|
||||
'Host': 'localhost',
|
||||
'Content-Length': '0',
|
||||
'Connection': 'close',
|
||||
},
|
||||
)
|
||||
|
||||
assert resp['status'] == 200, 'status'
|
||||
|
||||
def test_asgi_application_legacy_force(self):
|
||||
self.load('legacy_force', protocol='asgi')
|
||||
|
||||
resp = self.get(
|
||||
headers={
|
||||
'Host': 'localhost',
|
||||
'Content-Length': '0',
|
||||
'Connection': 'close',
|
||||
},
|
||||
)
|
||||
|
||||
assert resp['status'] == 200, 'status'
|
||||
|
||||
@@ -42,7 +42,8 @@ class TestApplicationPython(TestApplicationProto):
|
||||
"module": module,
|
||||
}
|
||||
|
||||
for attr in ('callable', 'home', 'limits', 'path', 'threads'):
|
||||
for attr in ('callable', 'home', 'limits', 'path', 'protocol',
|
||||
'threads'):
|
||||
if attr in kwargs:
|
||||
app[attr] = kwargs.pop(attr)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user