From 7ed7325d25d58994d9b2c568637832175e898912 Mon Sep 17 00:00:00 2001 From: Ciro Date: Tue, 15 Nov 2022 09:11:33 -0300 Subject: [PATCH] fix middleware with mixed async and sync --- examples/middleware_auto.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/middleware_auto.py b/examples/middleware_auto.py index 28b6670..1571362 100644 --- a/examples/middleware_auto.py +++ b/examples/middleware_auto.py @@ -9,7 +9,6 @@ def middleware(*functions): for function in functions: #detect if is coroutine or not if inspect.iscoroutinefunction(function): - data = await function(res, req, data) #in async query string, arguments and headers are only valid until the first await if not some_async_as_run: #get_headers will preserve headers (and cookies) inside req, after await @@ -20,6 +19,7 @@ def middleware(*functions): queries = req.get_queries() #mark to only grab header, params and queries one time some_async_as_run = True + data = await function(res, req, data) else: #call middlewares data = function(res, req, data) @@ -55,6 +55,6 @@ def home(res, req, user=None): res.end(user.get('greeting', None)) app = App() -app.get("/", middleware(auth, another_midie, home)) +app.get("/", middleware(auth, another_middie, home)) app.listen(3000, lambda config: print("Listening on port http://localhost:%d now\n" % config.port)) app.run() \ No newline at end of file