|
2 | 2 |
|
3 | 3 | #include "StrfryTemplates.h" |
4 | 4 | #include "app_git_version.h" |
| 5 | +#include "Favicon.h" |
5 | 6 |
|
6 | 7 |
|
7 | 8 |
|
8 | | -static std::string preGenerateHttpResponse(const std::string &contentType, const std::string &content) { |
| 9 | +static std::string preGenerateHttpResponse(const std::string &contentType, const std::string &content, const std::string &extraHeaders = "") { |
9 | 10 | std::string output = "HTTP/1.1 200 OK\r\n"; |
10 | 11 | output += std::string("Content-Type: ") + contentType + "\r\n"; |
11 | 12 | output += "Access-Control-Allow-Origin: *\r\n"; |
12 | 13 | output += "Connection: keep-alive\r\n"; |
13 | 14 | output += "Server: strfry\r\n"; |
14 | 15 | output += std::string("Content-Length: ") + std::to_string(content.size()) + "\r\n"; |
| 16 | + output += extraHeaders; |
15 | 17 | output += "\r\n"; |
16 | 18 | output += content; |
17 | 19 | return output; |
@@ -174,6 +176,8 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) { |
174 | 176 | return std::string_view(rendered); // memory only valid until next call |
175 | 177 | }; |
176 | 178 |
|
| 179 | + std::string faviconResponse = preGenerateHttpResponse("image/x-icon", favicon(), "Cache-Control: public, max-age=31536000\r\n"); |
| 180 | + |
177 | 181 |
|
178 | 182 | { |
179 | 183 | int extensionOptions = 0; |
@@ -202,6 +206,8 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) { |
202 | 206 | } else if (url == "/nodeinfo/2.1") { |
203 | 207 | auto nodeInfo = getNodeInfo21HttpResponse(); |
204 | 208 | res->write(nodeInfo.data(), nodeInfo.size()); |
| 209 | + } else if (url == "/favicon.ico") { |
| 210 | + res->write(faviconResponse.data(), faviconResponse.size()); |
205 | 211 | } else if (req.getHeader("accept").toStringView() == "application/nostr+json") { |
206 | 212 | auto info = getServerInfoHttpResponse(); |
207 | 213 | res->write(info.data(), info.size()); |
|
0 commit comments