in iep-admin/src/main/java/com/netflix/iep/admin/StaticResourceHandler.java [66:99]
public void handle(HttpExchange exchange) throws IOException {
String path = exchange.getRequestURI().getPath();
for (Map.Entry<String, String> entry : singlePagePaths.entrySet()) {
if (path.startsWith(entry.getKey())) {
LOGGER.debug("mapping {} to {}", path, entry.getValue());
path = "/" + entry.getValue();
}
}
exchange.getResponseHeaders().add("Content-Type", getContentType(path));
String resource = path.substring(1);
LOGGER.debug("loading resource {}", resource);
try (InputStream in = classLoader.getResourceAsStream(resource)) {
if (in == null) {
exchange.sendResponseHeaders(404, -1);
} else {
exchange.sendResponseHeaders(200, 0);
try (OutputStream out = exchange.getResponseBody()) {
byte[] buffer = new byte[4096];
int len;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
LOGGER.debug("failed to write resource " + resource, e);
}
}
} catch (Exception e) {
e.printStackTrace();
LOGGER.debug("failed to serve resource " + resource, e);
}
}