diff --git a/sanic/app.py b/sanic/app.py index e42c1210..bf00f247 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -958,7 +958,7 @@ class Sanic: if response is not None: try: response = await request.respond(response) - except: + except BaseException: # Skip response middleware request.stream.respond(response) await response.send(end_stream=True) diff --git a/sanic/compat.py b/sanic/compat.py index e6d0bc31..4e4094be 100644 --- a/sanic/compat.py +++ b/sanic/compat.py @@ -1,13 +1,16 @@ +from asyncio import CancelledError from sys import argv from multidict import CIMultiDict # type: ignore -from asyncio import CancelledError + try: from trio import Cancelled + CancelledErrors = CancelledError, Cancelled except ImportError: - CancelledErrors = CancelledError, + CancelledErrors = (CancelledError,) + class Header(CIMultiDict): def get_all(self, key): diff --git a/sanic/http.py b/sanic/http.py index 16a68685..ed498b85 100644 --- a/sanic/http.py +++ b/sanic/http.py @@ -145,7 +145,7 @@ class Http: request = self.protocol.request_class( url_bytes=self.url.encode(), headers=Header(headers), - version=protocol[-3:], + version=protocol[5:], method=method, transport=self.protocol.transport, app=self.protocol.app, diff --git a/sanic/request.py b/sanic/request.py index ce9e1b51..5a00cf54 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -8,8 +8,8 @@ from urllib.parse import parse_qs, parse_qsl, unquote, urlunparse from httptools import parse_url # type: ignore -from sanic.exceptions import InvalidUsage from sanic.compat import CancelledErrors +from sanic.exceptions import InvalidUsage from sanic.headers import ( parse_content_header, parse_forwarded, @@ -17,7 +17,7 @@ from sanic.headers import ( parse_xforwarded, ) from sanic.log import error_logger, logger -from sanic.response import HTTPResponse, BaseHTTPResponse +from sanic.response import BaseHTTPResponse, HTTPResponse try: @@ -128,8 +128,7 @@ class Request: raise except Exception: error_logger.exception( - "Exception occurred in one of response " - "middleware handlers" + "Exception occurred in one of response middleware handlers" ) return response