You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2022/07/08 20:20:06 UTC

[allura] branch db/require_method created (now f1017842f)

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a change to branch db/require_method
in repository https://gitbox.apache.org/repos/asf/allura.git


      at f1017842f Add generic require_method helper, alongside require_post

This branch includes the following new commits:

     new f1017842f Add generic require_method helper, alongside require_post

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[allura] 01/01: Add generic require_method helper, alongside require_post

Posted by br...@apache.org.
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 <db...@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):
     '''