workaround fix for an issue in aiohttp.Client
This commit is contained in:
@@ -156,6 +156,8 @@ class MethodNotSupported(SanicException):
|
||||
super().__init__(message)
|
||||
self.headers = dict()
|
||||
self.headers["Allow"] = ", ".join(allowed_methods)
|
||||
if method in ['HEAD', 'PATCH', 'PUT', 'DELETE']:
|
||||
self.headers['Content-Length'] = 0
|
||||
|
||||
|
||||
@add_status_code(500)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import traceback
|
||||
from json import JSONDecodeError
|
||||
from sanic.log import logger
|
||||
from sanic.exceptions import MethodNotSupported
|
||||
from sanic.response import text
|
||||
|
||||
|
||||
HOST = '127.0.0.1'
|
||||
@@ -54,6 +56,13 @@ class SanicTestClient:
|
||||
results[0] = request
|
||||
self.app.request_middleware.appendleft(_collect_request)
|
||||
|
||||
@self.app.exception(MethodNotSupported)
|
||||
async def error_handler(request, exception):
|
||||
if request.method in ['HEAD', 'PATCH', 'PUT', 'DELETE']:
|
||||
return text('', exception.status_code, headers=exception.headers)
|
||||
else:
|
||||
return self.app.error_handler.default(request, exception)
|
||||
|
||||
@self.app.listener('after_server_start')
|
||||
async def _collect_response(sanic, loop):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user