]> foleosoft.com Git - RosadoAPI.git/commitdiff
Mon Jan 20 03:17:58 PM EST 2025
authormiha-q <>
Mon, 20 Jan 2025 20:17:58 +0000 (15:17 -0500)
committermiha-q <>
Mon, 20 Jan 2025 20:17:58 +0000 (15:17 -0500)
src/http.c
src/main.c

index 1ba45a7e58e5fbca01fb0d31d49904f58038169a..6316f77580a0e9d0266335cdd55588ef655121e3 100644 (file)
@@ -349,6 +349,25 @@ int httpStringOut(int session_fd, char* str)
        httpRespond(session_fd, "\n");
 }
 
+int httpStringOutByType(int session_fd, char* str, const char* type)
+{
+       //Good header
+       httpRespond(session_fd, "HTTP/1.1 200 OK\n");
+       httpRespond(session_fd, HTTP_SERVER);
+
+       int strSize = strlen(str);
+       //Spit out file content length part of the HTTP message
+       const char *contentLengthTemplate = "Access-Control-Allow-Origin: *\nContent-Type: %s\nContent-Length: %i\n\n";
+       int contentLengthLen = snprintf(NULL, 0, contentLengthTemplate, type, strSize);
+       char* contentLength = malloc(contentLengthLen + 1);
+       sprintf(contentLength, contentLengthTemplate, strSize);
+       httpRespond(session_fd, contentLength);
+       free(contentLength);
+
+       httpRespond(session_fd, str);
+       httpRespond(session_fd, "\n");
+}
+
 void httpRequest(int session_fd, char** str, int* strlen)
 {
        int flags = fcntl(session_fd, F_GETFL, 0);
index d62ab2bdd5887e4a67d801b4209ce2e72b888dca..8f686ff0f8de652386565f9b4aaff5c2dd6fd29c 100644 (file)
@@ -379,7 +379,7 @@ void *handleRequest(void *vargp)
                                uint8_t* frontend = malloc(sizeof(FAVICON) + 1);
                                memcpy(frontend, FAVICON, sizeof(FAVICON));
                                frontend[sizeof(FAVICON)] = 0;
-                               httpStringOut(session_fd, frontend);
+                               httpStringOutByType(session_fd, frontend, "image/x-icon");
                                free(frontend);
                        }
                        else