Fix index HEAD requests
Index HEAD requests incorrectly return a content-length header of 0. This commit addresses this by removing the special handling for index HEAD requests, and just relying on the general mechanism that exists for handling HEAD requests in the REST layer. Relates #23112
This commit is contained in:
parent
5808aea265
commit
a6158398dd
|
@ -252,7 +252,6 @@ import org.elasticsearch.rest.action.admin.indices.RestHeadIndexTemplateAction;
|
|||
import org.elasticsearch.rest.action.admin.indices.RestIndexDeleteAliasesAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestIndexPutAliasAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestIndicesAliasesAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestIndicesExistsAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestIndicesSegmentsAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestIndicesShardStoresAction;
|
||||
import org.elasticsearch.rest.action.admin.indices.RestIndicesStatsAction;
|
||||
|
@ -527,7 +526,6 @@ public class ActionModule extends AbstractModule {
|
|||
registerHandler.accept(new RestDeleteSnapshotAction(settings, restController));
|
||||
registerHandler.accept(new RestSnapshotsStatusAction(settings, restController));
|
||||
|
||||
registerHandler.accept(new RestIndicesExistsAction(settings, restController));
|
||||
registerHandler.accept(new RestTypesExistsAction(settings, restController));
|
||||
registerHandler.accept(new RestGetIndicesAction(settings, restController, indexScopedSettings, settingsFilter));
|
||||
registerHandler.accept(new RestIndicesStatsAction(settings, restController));
|
||||
|
|
|
@ -46,6 +46,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.HEAD;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
public class RestGetIndicesAction extends BaseRestHandler {
|
||||
|
@ -58,6 +59,7 @@ public class RestGetIndicesAction extends BaseRestHandler {
|
|||
super(settings);
|
||||
this.indexScopedSettings = indexScopedSettings;
|
||||
controller.registerHandler(GET, "/{index}", this);
|
||||
controller.registerHandler(HEAD, "/{index}", this);
|
||||
controller.registerHandler(GET, "/{index}/{type}", this);
|
||||
this.settingsFilter = settingsFilter;
|
||||
}
|
||||
|
|
|
@ -1,67 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.rest.action.admin.indices;
|
||||
|
||||
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest;
|
||||
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsResponse;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.client.node.NodeClient;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.BytesRestResponse;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.action.RestResponseListener;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.HEAD;
|
||||
import static org.elasticsearch.rest.RestStatus.NOT_FOUND;
|
||||
import static org.elasticsearch.rest.RestStatus.OK;
|
||||
|
||||
public class RestIndicesExistsAction extends BaseRestHandler {
|
||||
public RestIndicesExistsAction(Settings settings, RestController controller) {
|
||||
super(settings);
|
||||
controller.registerHandler(HEAD, "/{index}", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
|
||||
IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
IndicesOptions indicesOptions = IndicesOptions.fromRequest(request, indicesExistsRequest.indicesOptions());
|
||||
indicesExistsRequest.expandWilcardsOpen(indicesOptions.expandWildcardsOpen());
|
||||
indicesExistsRequest.expandWilcardsClosed(indicesOptions.expandWildcardsClosed());
|
||||
indicesExistsRequest.local(request.paramAsBoolean("local", indicesExistsRequest.local()));
|
||||
return channel -> client.admin().indices().exists(indicesExistsRequest, new RestResponseListener<IndicesExistsResponse>(channel) {
|
||||
@Override
|
||||
public RestResponse buildResponse(IndicesExistsResponse response) {
|
||||
if (response.isExists()) {
|
||||
return new BytesRestResponse(OK, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY);
|
||||
} else {
|
||||
return new BytesRestResponse(NOT_FOUND, BytesRestResponse.TEXT_CONTENT_TYPE, BytesArray.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -54,8 +54,8 @@ public class Netty4HeadBodyIsEmptyIT extends ESRestTestCase {
|
|||
|
||||
public void testIndexExists() throws IOException {
|
||||
createTestDoc();
|
||||
headTestCase("test", emptyMap(), equalTo(0));
|
||||
headTestCase("test", singletonMap("pretty", "true"), equalTo(0));
|
||||
headTestCase("test", emptyMap(), greaterThan(0));
|
||||
headTestCase("test", singletonMap("pretty", "true"), greaterThan(0));
|
||||
}
|
||||
|
||||
public void testTypeExists() throws IOException {
|
||||
|
|
Loading…
Reference in New Issue