From c944c6ed6332b3a776683e300c99e5529b395901 Mon Sep 17 00:00:00 2001 From: Win Date: Fri, 24 May 2024 20:03:15 +0700 Subject: [PATCH] mimetype check beta --- src/file.c | 24 ++++++++++++++++++++++++ src/file.h | 1 + 2 files changed, 25 insertions(+) diff --git a/src/file.c b/src/file.c index 626bf62..df167e6 100644 --- a/src/file.c +++ b/src/file.c @@ -24,5 +24,29 @@ void get_file_path(char *uri, char *file_path) { } void get_mime_type(char *file, char *mime) { + const char *dot = strrchr(file, '.'); + + if (dot == NULL) + strcpy(mime, "text/html"); + + else if (strcmp(dot, ".html") == 0) + strcpy(mime, "text/html"); + else if (strcmp(dot, ".css") == 0) + strcpy(mime, "text/css"); + + else if (strcmp(dot, ".js") == 0) + strcpy(mime, "application/js"); + + else if (strcmp(dot, ".jpg") == 0) + strcpy(mime, "image/jpeg"); + + else if (strcmp(dot, ".png") == 0) + strcpy(mime, "image/png"); + + else if (strcmp(dot, ".gif") == 0) + strcpy(mime, "image/gif"); + + else + strcpy(mime, "text/html"); } diff --git a/src/file.h b/src/file.h index e115710..bc67e5a 100644 --- a/src/file.h +++ b/src/file.h @@ -1,3 +1,4 @@ #define MAX_PATH_SIZE 4096 void get_file_path(char *uri, char *file_path); +void get_mime_type(char *file, char *mime);