From 4cc3133d779b1b50818faa146a6bbac6cdff1fa0 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Wed, 5 Nov 2025 14:16:21 -0500 Subject: [PATCH] Support previous extension point signature as well Signed-off-by: Craig Perkins --- .../org/opensearch/plugins/ActionPlugin.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/server/src/main/java/org/opensearch/plugins/ActionPlugin.java b/server/src/main/java/org/opensearch/plugins/ActionPlugin.java index 6bcb5ccd3a691..a9abdb7b4bb77 100644 --- a/server/src/main/java/org/opensearch/plugins/ActionPlugin.java +++ b/server/src/main/java/org/opensearch/plugins/ActionPlugin.java @@ -150,6 +150,32 @@ default Collection getTaskHeaders() { * Note: Only one installed plugin may implement a rest wrapper. */ default UnaryOperator getRestHandlerWrapper(ThreadContext threadContext, Set headersToCopy) { + return this.getRestHandlerWrapper(threadContext); + } + + /** + * Returns a function used to wrap each rest request before handling the request. + * The returned {@link UnaryOperator} is called for every incoming rest request and receives + * the original rest handler as it's input. This allows adding arbitrary functionality around + * rest request handlers to do for instance logging or authentication. + * A simple example of how to only allow GET request is here: + *
+     * {@code
+     *    UnaryOperator getRestHandlerWrapper(ThreadContext threadContext) {
+     *      return originalHandler -> (RestHandler) (request, channel, client) -> {
+     *        if (request.method() != Method.GET) {
+     *          throw new IllegalStateException("only GET requests are allowed");
+     *        }
+     *        originalHandler.handleRequest(request, channel, client);
+     *      };
+     *    }
+     * }
+     * 
+ * + * Note: Only one installed plugin may implement a rest wrapper. + */ + @Deprecated(forRemoval = true) + default UnaryOperator getRestHandlerWrapper(ThreadContext threadContext) { return null; }