|
16 | 16 | import org.elasticsearch.common.settings.Setting.Property; |
17 | 17 | import org.elasticsearch.common.util.set.Sets; |
18 | 18 | import org.elasticsearch.core.CheckedConsumer; |
| 19 | +import org.elasticsearch.core.Nullable; |
19 | 20 | import org.elasticsearch.core.RefCounted; |
20 | 21 | import org.elasticsearch.core.Releasable; |
21 | 22 | import org.elasticsearch.core.RestApiVersion; |
@@ -104,6 +105,8 @@ public final void handleRequest(RestRequest request, RestChannel channel, NodeCl |
104 | 105 | // prepare the request for execution; has the side effect of touching the request parameters |
105 | 106 | try (var action = prepareRequest(request, client)) { |
106 | 107 |
|
| 108 | + assert assertConsumesSupportedParams(supported, request); |
| 109 | + |
107 | 110 | // validate unconsumed params, but we must exclude params used to format the response |
108 | 111 | // use a sorted set so the unconsumed parameters appear in a reliable sorted order |
109 | 112 | final SortedSet<String> unconsumedParams = request.unconsumedParams() |
@@ -148,6 +151,20 @@ public void close() { |
148 | 151 | } |
149 | 152 | } |
150 | 153 |
|
| 154 | + private boolean assertConsumesSupportedParams(@Nullable Set<String> supported, RestRequest request) { |
| 155 | + if (supported != null) { |
| 156 | + final var supportedAndCommon = new TreeSet<>(supported); |
| 157 | + supportedAndCommon.add("error_trace"); |
| 158 | + supportedAndCommon.addAll(ALWAYS_SUPPORTED); |
| 159 | + supportedAndCommon.removeAll(RestRequest.INTERNAL_MARKER_REQUEST_PARAMETERS); |
| 160 | + final var consumed = new TreeSet<>(request.consumedParams()); |
| 161 | + consumed.removeAll(RestRequest.INTERNAL_MARKER_REQUEST_PARAMETERS); |
| 162 | + assert supportedAndCommon.equals(consumed) |
| 163 | + : getName() + ": consumed params " + consumed + " while supporting " + supportedAndCommon; |
| 164 | + } |
| 165 | + return true; |
| 166 | + } |
| 167 | + |
151 | 168 | protected static String unrecognized(RestRequest request, Set<String> invalids, Set<String> candidates, String detail) { |
152 | 169 | StringBuilder message = new StringBuilder().append("request [") |
153 | 170 | .append(request.path()) |
|
0 commit comments