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);