Add favicon

This commit is contained in:
Robert Muir 2015-08-22 00:16:36 -04:00
parent 91e722d5e6
commit 91d16f45c6
3 changed files with 30 additions and 2 deletions

View File

@ -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<HttpServer> {
}
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<HttpServer> {
}
}
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));

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -875,10 +875,16 @@
<version>2.4.1</version>
</plugin>
<plugin>
<!-- We just declare which plugin version to use. Each project can have then its own settings -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<!-- add some additonal binary types to prevent maven from
screwing them up with resource filtering -->
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>ico</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>