From b1b801f24503bab4b1cbf2a94eadaea9fac30546 Mon Sep 17 00:00:00 2001 From: PandaFeeder Date: Sat, 13 May 2017 18:58:35 +0800 Subject: [PATCH] fix stupid handler has no _request/response_middleware attribut error --- sanic/app.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sanic/app.py b/sanic/app.py index e740408b..0828191a 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -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)