From: miha-q <> Date: Mon, 20 Jan 2025 20:17:58 +0000 (-0500) Subject: Mon Jan 20 03:17:58 PM EST 2025 X-Git-Url: http://www.foleosoft.com/?a=commitdiff_plain;h=09f1380e3486dd648ac1afd1748c5689c08a06c8;p=RosadoAPI.git Mon Jan 20 03:17:58 PM EST 2025 --- diff --git a/src/http.c b/src/http.c index 1ba45a7..6316f77 100644 --- a/src/http.c +++ b/src/http.c @@ -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); diff --git a/src/main.c b/src/main.c index d62ab2b..8f686ff 100644 --- a/src/main.c +++ b/src/main.c @@ -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