Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions server/src/main/java/org/opensearch/plugins/ActionPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,32 @@ default Collection<String> getTaskHeaders() {
* Note: Only one installed plugin may implement a rest wrapper.
*/
default UnaryOperator<RestHandler> getRestHandlerWrapper(ThreadContext threadContext, Set<RestHeaderDefinition> 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:
* <pre>
* {@code
* UnaryOperator<RestHandler> 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);
* };
* }
* }
* </pre>
*
* Note: Only one installed plugin may implement a rest wrapper.
*/
@Deprecated(forRemoval = true)
default UnaryOperator<RestHandler> getRestHandlerWrapper(ThreadContext threadContext) {
return null;
}

Expand Down
Loading