diff --git a/core/src/main/java/org/elasticsearch/http/HttpServer.java b/core/src/main/java/org/elasticsearch/http/HttpServer.java index 40067e2bff3..0fab142ac18 100644 --- a/core/src/main/java/org/elasticsearch/http/HttpServer.java +++ b/core/src/main/java/org/elasticsearch/http/HttpServer.java @@ -20,6 +20,7 @@ package org.elasticsearch.http; import com.google.common.collect.ImmutableMap; +import com.google.common.io.ByteStreams; import org.elasticsearch.common.component.AbstractLifecycleComponent; import org.elasticsearch.common.inject.Inject; @@ -30,6 +31,7 @@ import org.elasticsearch.node.service.NodeService; import org.elasticsearch.rest.*; import java.io.IOException; +import java.io.InputStream; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.HashMap; @@ -114,10 +116,14 @@ public class HttpServer extends AbstractLifecycleComponent { } public void internalDispatchRequest(final HttpRequest request, final HttpChannel channel) { - if (request.rawPath().startsWith("/_plugin/")) { + String rawPath = request.rawPath(); + if (rawPath.startsWith("/_plugin/")) { RestFilterChain filterChain = restController.filterChain(pluginSiteFilter); filterChain.continueProcessing(request, channel); return; + } else if (rawPath.equals("/favicon.ico")) { + handleFavicon(request, channel); + return; } restController.dispatchRequest(request, channel); } @@ -131,6 +137,22 @@ public class HttpServer extends AbstractLifecycleComponent { } } + void handleFavicon(HttpRequest request, HttpChannel channel) { + if (request.method() == RestRequest.Method.GET) { + try { + try (InputStream stream = getClass().getResourceAsStream("/config/favicon.ico")) { + byte[] content = ByteStreams.toByteArray(stream); + BytesRestResponse restResponse = new BytesRestResponse(RestStatus.OK, "image/x-icon", content); + channel.sendResponse(restResponse); + } + } catch (IOException e) { + channel.sendResponse(new BytesRestResponse(INTERNAL_SERVER_ERROR)); + } + } else { + channel.sendResponse(new BytesRestResponse(FORBIDDEN)); + } + } + void handlePluginSite(HttpRequest request, HttpChannel channel) throws IOException { if (disableSites) { channel.sendResponse(new BytesRestResponse(FORBIDDEN)); diff --git a/core/src/main/resources/config/favicon.ico b/core/src/main/resources/config/favicon.ico new file mode 100644 index 00000000000..0eabd4c1edb Binary files /dev/null and b/core/src/main/resources/config/favicon.ico differ diff --git a/pom.xml b/pom.xml index 13bda58932d..8295e8ebe86 100644 --- a/pom.xml +++ b/pom.xml @@ -875,10 +875,16 @@ 2.4.1 - org.apache.maven.plugins maven-resources-plugin 2.7 + + + + ico + + org.apache.maven.plugins