fix stupid handler has no _request/response_middleware attribut error

This commit is contained in:
PandaFeeder 2017-05-13 18:58:35 +08:00
parent ce4e7437de
commit b1b801f245

View File

@ -128,7 +128,7 @@ class Sanic:
# attach middleware to specific handler
if middleware:
for r in ('request', 'response'):
mid = middleware[r]
mid = middleware.setdefault(r, None)
if mid:
if callable(mid):
vars(handler)["_"+r+"_middleware"] = mid,
@ -139,6 +139,8 @@ class Sanic:
"Middleware mounted on a handler should "
"be a function or a sequence of functions"
)
else:
vars(handler)["_"+r+"_middleware"] = ()
self.router.add(uri=uri, methods=methods, handler=handler,
host=host, strict_slashes=strict_slashes)