From 91d16f45c65e07e727d290d30665885a16fe1a39 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 22 Aug 2015 00:16:36 -0400 Subject: [PATCH] Add favicon --- .../org/elasticsearch/http/HttpServer.java | 24 +++++++++++++++++- core/src/main/resources/config/favicon.ico | Bin 0 -> 1150 bytes pom.xml | 8 +++++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 core/src/main/resources/config/favicon.ico 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 0000000000000000000000000000000000000000..0eabd4c1edbe4b408731f9ccf5b7c3fb6b8feb2a GIT binary patch literal 1150 zcmbu8Ye*DP6vwZaW)WqDmMLg~m5@;`K7s@(`;e%8Dia0$5=az%Ff6l&DP~BRksuM7 z&op1nwmwK(cU`fESeYxDu8O!1Wm9W)#zlACe`kE5OZ25X{AcFQo!|eQb2*nW2fAEc z84Vwnw23iydOJ)KKlzXxmhOy&(VG1L;9#fB5nbg#uO`qW?n8o0@`5ZzS>o!L}w=ixZ2uNyCxZpPcz0OF6YskY@1x;svyUe}JDiYH)o zmyk2oLHNeH`?QZ|pI0-;ltF8(=)<)hLw(a;d^d2oH)Ft^@lJdbCg+LwU*{2H5(dl- zT@sW@cTnzuD;@!;dw&F#P1|8GHlqDQEy|u>#N$XcEX#7kha#noI-L}~0r@N;8O zY9dg|Z6jWS@&-3lNf}_uL34c`ypA)3o?|!>$q;y!LEW!X_ce1HEwIX5!n4TFzX0kVqhBNpR-}dqK&#|wc)M*DCardAL(*0a;Yb(RR zn;OK=5XafT8U*ZWog)tcK?A@jKaGqOKV;-aQ~8J$_uxxSkx-Nv0#(6POvtNHVI;0` z0j}~nxD)F}+M^IXczAXK{esO*+UW1 zG0d)Gmpq#DEV#h5c<8Bz@|_v`hvwnjvdpdWqMw*U#kh5x_zh>`m%&*+{mF1ti$(L5SnFqP{qwEM`kXBoBE|L6}r%KbtB literal 0 HcmV?d00001 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