@@ -144,6 +144,7 @@ void not_found(resp_https_t response, req_https_t request) {
144144 << data.str ();
145145}
146146
147+ // todo - combine these functions into a single function that accepts the page, i.e "index", "pin", "apps"
147148void getIndexPage (resp_https_t response, req_https_t request) {
148149 if (!authenticate (response, request)) return ;
149150
@@ -229,6 +230,8 @@ void getTroubleshootingPage(resp_https_t response, req_https_t request) {
229230}
230231
231232void getFaviconImage (resp_https_t response, req_https_t request) {
233+ // todo - combine function with getSunshineLogoImage and possibly getNodeModules
234+ // todo - use mime_types map
232235 print_req (request);
233236
234237 std::ifstream in (WEB_DIR " images/favicon.ico" , std::ios::binary);
@@ -238,6 +241,8 @@ void getFaviconImage(resp_https_t response, req_https_t request) {
238241}
239242
240243void getSunshineLogoImage (resp_https_t response, req_https_t request) {
244+ // todo - combine function with getFaviconImage and possibly getNodeModules
245+ // todo - use mime_types map
241246 print_req (request);
242247
243248 std::ifstream in (WEB_DIR " images/logo-sunshine-45.png" , std::ios::binary);
@@ -269,17 +274,18 @@ void getNodeModules(resp_https_t response, req_https_t request) {
269274 }
270275 else {
271276 auto relPath = fs::relative (filePath, webDirPath);
272- if (relPath.extension () == " .ttf" or relPath.extension () == " .woff2" ) {
273- // Fonts are read differntly
277+ // get the mime type from the file extension mime_types map
278+ // remove the leading period from the extension
279+ auto mimeType = mime_types.find (relPath.extension ().string ().substr (1 ));
280+ // check if the extension is in the map at the x position
281+ if (mimeType != mime_types.end ()) {
282+ // if it is, set the content type to the mime type
274283 SimpleWeb::CaseInsensitiveMultimap headers;
275- std::ifstream in ((filePath). c_str (), std::ios::binary );
276- headers. emplace ( " Content-Type " , " font/ " + filePath.extension (). string (). substr ( 1 ) );
284+ headers. emplace ( " Content-Type " , mimeType-> second );
285+ std::ifstream in ( filePath.string (), std::ios::binary );
277286 response->write (SimpleWeb::StatusCode::success_ok, in, headers);
278287 }
279- else {
280- std::string content = read_file ((filePath.string ()).c_str ());
281- response->write (content);
282- }
288+ // do not return any file if the type is not in the map
283289 }
284290}
285291
0 commit comments