revert change on listing plugins on /_plugin

we should provide it as part of nodes info
relates to #2664
This commit is contained in:
Shay Banon 2013-03-03 21:52:44 +01:00
parent a7da27c714
commit a1b2434339

View File

@ -21,15 +21,12 @@ package org.elasticsearch.http;
import com.google.common.collect.ImmutableMap;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.component.AbstractLifecycleComponent;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.env.Environment;
import org.elasticsearch.node.service.NodeService;
import org.elasticsearch.plugins.PluginsHelper;
import org.elasticsearch.rest.*;
import java.io.File;
@ -37,7 +34,6 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.elasticsearch.rest.RestStatus.*;
/**
@ -148,39 +144,17 @@ public class HttpServer extends AbstractLifecycleComponent<HttpServer> {
channel.sendResponse(new StringRestResponse(FORBIDDEN));
return;
}
// TODO for a "/_plugin" endpoint, we should have a page that lists all the plugins?
String path = request.rawPath().substring("/_plugin/".length());
int i1 = path.indexOf('/');
String pluginName;
String sitePath;
if (i1 == -1) {
// If user tries to reach "/_plugin/" endpoint, we display a page that lists all the plugins #2664
if (!Strings.hasText(path)) {
try {
XContentBuilder json = jsonBuilder();
if (request.hasParam("pretty")) {
json.prettyPrint();
}
json.startObject().startArray("sites");
for(String plugin : PluginsHelper.sitePlugins(environment)) {
json.startObject()
.field("name", plugin)
.field("url", "/_plugin/" + plugin +"/")
.endObject();
}
json.endArray().endObject();
channel.sendResponse(new BytesRestResponse(json.bytes().toBytes(),
guessMimeType(guessMimeType("index.json"))));
} catch (IOException e) {
channel.sendResponse(new StringRestResponse(INTERNAL_SERVER_ERROR));
}
return;
}
pluginName = path;
sitePath = null;
// If a trailing / is missing, we redirect to the right page #2654
channel.sendResponse(new HttpRedirectRestResponse(request.rawPath()+"/"));
channel.sendResponse(new HttpRedirectRestResponse(request.rawPath() + "/"));
return;
} else {
pluginName = path.substring(0, i1);
@ -217,6 +191,7 @@ public class HttpServer extends AbstractLifecycleComponent<HttpServer> {
}
}
// TODO: Don't respond with a mime type that violates the request's Accept header
private String guessMimeType(String path) {
int lastDot = path.lastIndexOf('.');