Skip to content

Commit

Permalink
Specify some parameters as always supported by capabilities (#108461)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoop committed May 10, 2024
1 parent da50207 commit bc37ecf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java
Expand Up @@ -76,13 +76,18 @@ public final long getUsageCount() {
@Override
public abstract List<Route> routes();

private static final Set<String> ALWAYS_SUPPORTED = Set.of("format", "filter_path", "pretty", "human");

@Override
public final void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
// check if the query has any parameters that are not in the supported set (if declared)
Set<String> supported = supportedQueryParameters();
if (supported != null && supported.containsAll(request.params().keySet()) == false) {
Set<String> unsupported = Sets.difference(request.params().keySet(), supported);
throw new IllegalArgumentException(unrecognized(request, unsupported, supported, "parameter"));
if (supported != null) {
var allSupported = Sets.union(ALWAYS_SUPPORTED, supported);
if (allSupported.containsAll(request.params().keySet()) == false) {
Set<String> unsupported = Sets.difference(request.params().keySet(), allSupported);
throw new IllegalArgumentException(unrecognized(request, unsupported, allSupported, "parameter"));
}
}

// prepare the request for execution; has the side effect of touching the request parameters
Expand Down

0 comments on commit bc37ecf

Please sign in to comment.