fix stupid handler has no _request/response_middleware attribut error
This commit is contained in:
parent
ce4e7437de
commit
b1b801f245
|
@ -128,7 +128,7 @@ class Sanic:
|
||||||
# attach middleware to specific handler
|
# attach middleware to specific handler
|
||||||
if middleware:
|
if middleware:
|
||||||
for r in ('request', 'response'):
|
for r in ('request', 'response'):
|
||||||
mid = middleware[r]
|
mid = middleware.setdefault(r, None)
|
||||||
if mid:
|
if mid:
|
||||||
if callable(mid):
|
if callable(mid):
|
||||||
vars(handler)["_"+r+"_middleware"] = mid,
|
vars(handler)["_"+r+"_middleware"] = mid,
|
||||||
|
@ -139,6 +139,8 @@ class Sanic:
|
||||||
"Middleware mounted on a handler should "
|
"Middleware mounted on a handler should "
|
||||||
"be a function or a sequence of functions"
|
"be a function or a sequence of functions"
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
vars(handler)["_"+r+"_middleware"] = ()
|
||||||
|
|
||||||
self.router.add(uri=uri, methods=methods, handler=handler,
|
self.router.add(uri=uri, methods=methods, handler=handler,
|
||||||
host=host, strict_slashes=strict_slashes)
|
host=host, strict_slashes=strict_slashes)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user