This is an automated email from the ASF dual-hosted git repository. brondsem pushed a commit to branch db/require_method in repository https://gitbox.apache.org/repos/asf/allura.git
commit f1017842f1879afa6fc29e62ec648c8b2bd4ef2f Author: Dave Brondsema <dbronds...@slashdotmedia.com> AuthorDate: Fri Jul 8 16:19:54 2022 -0400 Add generic require_method helper, alongside require_post --- Allura/allura/lib/decorators.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Allura/allura/lib/decorators.py b/Allura/allura/lib/decorators.py index 241164afb..078eaa4f8 100644 --- a/Allura/allura/lib/decorators.py +++ b/Allura/allura/lib/decorators.py @@ -115,6 +115,20 @@ class require_post: return func +def require_method(*methods): + """ + Usage: + + @require_method('GET', 'HEAD') + def foo() + """ + def check_methods(func, *args, **kwargs): + if request.method not in methods: + raise exc.HTTPMethodNotAllowed(headers={'Allow': str(','.join(methods))}) + return func(*args, **kwargs) + return decorator(check_methods) + + @decorator def reconfirm_auth(func, *args, **kwargs): '''