Example ASGI apps now ensure scope['type'] is expected message type. (#348)

This commit is contained in:
Tom Christie 2019-01-25 14:40:33 +00:00 committed by GitHub
parent 16db18f519
commit d5c798e6b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 0 deletions

View File

@ -100,6 +100,7 @@ from starlette.responses import PlainTextResponse
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):

View File

@ -13,6 +13,7 @@ from starlette.response import Response
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):
@ -95,6 +96,7 @@ from starlette.responses import Response
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):

View File

@ -24,6 +24,7 @@ from starlette.responses import Response
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):
@ -62,6 +63,7 @@ from starlette.responses import HTMLResponse
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):
@ -79,6 +81,7 @@ from starlette.responses import PlainTextResponse
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):
@ -107,6 +110,7 @@ env = Environment(loader=FileSystemLoader('templates'))
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):
@ -141,6 +145,7 @@ from starlette.responses import JSONResponse
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):
@ -164,6 +169,7 @@ from starlette.responses import UJSONResponse
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):
@ -181,6 +187,7 @@ from starlette.responses import PlainTextResponse, RedirectResponse
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):
@ -210,6 +217,7 @@ async def slow_numbers(minimum, maximum):
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):
@ -237,6 +245,7 @@ from starlette.responses import FileResponse
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):

View File

@ -9,6 +9,7 @@ from starlette.testclient import TestClient
class App:
def __init__(self, scope):
assert scope['type'] == 'http'
self.scope = scope
async def __call__(self, receive, send):
@ -49,6 +50,7 @@ from starlette.websockets import WebSocket
class App:
def __init__(self, scope):
assert scope['type'] == 'websocket'
self.scope = scope
async def __call__(self, receive, send):

View File

@ -12,6 +12,7 @@ from starlette.websockets import WebSocket
class App:
def __init__(self, scope):
assert scope['type'] == 'websocket'
self.scope = scope
async def __call__(self, receive, send):