Make sure ASGI ws subprotocols is a list (#2127)
* Ensure protocols is a list for ASGI * Subprotocol updates
This commit is contained in:
21
sanic/app.py
21
sanic/app.py
@@ -585,7 +585,12 @@ class Sanic(BaseSanic):
|
||||
# determine if the parameter supplied by the caller
|
||||
# passes the test in the URL
|
||||
if param_info.pattern:
|
||||
passes_pattern = param_info.pattern.match(supplied_param)
|
||||
pattern = (
|
||||
param_info.pattern[1]
|
||||
if isinstance(param_info.pattern, tuple)
|
||||
else param_info.pattern
|
||||
)
|
||||
passes_pattern = pattern.match(supplied_param)
|
||||
if not passes_pattern:
|
||||
if param_info.cast != str:
|
||||
msg = (
|
||||
@@ -593,13 +598,13 @@ class Sanic(BaseSanic):
|
||||
f"for parameter `{param_info.name}` does "
|
||||
"not match pattern for type "
|
||||
f"`{param_info.cast.__name__}`: "
|
||||
f"{param_info.pattern.pattern}"
|
||||
f"{pattern.pattern}"
|
||||
)
|
||||
else:
|
||||
msg = (
|
||||
f'Value "{supplied_param}" for parameter '
|
||||
f"`{param_info.name}` does not satisfy "
|
||||
f"pattern {param_info.pattern.pattern}"
|
||||
f"pattern {pattern.pattern}"
|
||||
)
|
||||
raise URLBuildError(msg)
|
||||
|
||||
@@ -740,17 +745,14 @@ class Sanic(BaseSanic):
|
||||
|
||||
if response:
|
||||
response = await request.respond(response)
|
||||
else:
|
||||
elif not hasattr(handler, "is_websocket"):
|
||||
response = request.stream.response # type: ignore
|
||||
# Make sure that response is finished / run StreamingHTTP callback
|
||||
|
||||
# Make sure that response is finished / run StreamingHTTP callback
|
||||
if isinstance(response, BaseHTTPResponse):
|
||||
await response.send(end_stream=True)
|
||||
else:
|
||||
try:
|
||||
# Fastest method for checking if the property exists
|
||||
handler.is_websocket # type: ignore
|
||||
except AttributeError:
|
||||
if not hasattr(handler, "is_websocket"):
|
||||
raise ServerError(
|
||||
f"Invalid response type {response!r} "
|
||||
"(need HTTPResponse)"
|
||||
@@ -777,6 +779,7 @@ class Sanic(BaseSanic):
|
||||
|
||||
if self.asgi:
|
||||
ws = request.transport.get_websocket_connection()
|
||||
await ws.accept(subprotocols)
|
||||
else:
|
||||
protocol = request.transport.get_protocol()
|
||||
protocol.app = self
|
||||
|
||||
Reference in New Issue
Block a user