Skip to content

Commit

Permalink
Add favicon
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba6000 committed Sep 2, 2024
1 parent 4f33952 commit 99dd783
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
Binary file added example_website/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions example_website/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<title>AE2</title>
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/kuba6000/ae2webintegration/AE2Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.concurrent.Future;
import java.util.stream.Collectors;

import org.apache.commons.io.IOUtils;

import com.kuba6000.ae2webintegration.ae2request.async.GetTracking;
import com.kuba6000.ae2webintegration.ae2request.async.GetTrackingHistory;
import com.kuba6000.ae2webintegration.ae2request.async.IAsyncRequest;
Expand Down Expand Up @@ -271,6 +273,23 @@ public void handle(HttpExchange t) throws IOException {
&& !path.equals("/index.asp")
&& !path.equals("/index.aspx")
&& !path.equals("/index.jsp")) {

if (path.equals("/favicon.ico")) {
t.getResponseHeaders()
.set("Content-Type", "image/x-icon");
try (InputStream is = AE2Controller.class.getResourceAsStream("/assets/favicon.ico")) {
if (is == null) return;

byte[] raw_response = IOUtils.toByteArray(is);
is.read(raw_response);
t.sendResponseHeaders(200, raw_response.length);
OutputStream os = t.getResponseBody();
os.write(raw_response);
os.close();
}
return;
}

String response = "<h1>Invalid url! (ERROR 404)</h1>";
byte[] raw_response = response.getBytes();
t.sendResponseHeaders(404, raw_response.length);
Expand Down
Binary file added src/main/resources/assets/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions src/main/resources/assets/webpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
color: black;
}
</style>
<link rel="icon" type="image/x-icon" href="favicon.ico" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<title>AE2</title>
Expand Down

0 comments on commit 99dd783

Please sign in to comment.