workaround fix for an issue in aiohttp.Client

This commit is contained in:
Yun Xu
2018-02-27 21:42:41 -08:00
parent d55e453bd5
commit c39ddd00d3
3 changed files with 21 additions and 1 deletions

View File

@@ -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)

View File

@@ -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: