From 5c451db7e75181aae3f7b2f48406b28e7bba7c77 Mon Sep 17 00:00:00 2001 From: Andrea Smith Date: Sun, 15 Nov 2020 15:02:01 -0600 Subject: Added getContentType --- P3/server.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'P3') diff --git a/P3/server.c b/P3/server.c index f99094f..80c4448 100644 --- a/P3/server.c +++ b/P3/server.c @@ -77,14 +77,31 @@ void initCache(){ char* getContentType(char * mybuf) { // Should return the content type based on the file type in the request // (See Section 5 in Project description for more details) + char* ext = strrchr(mybuf, '.'); - + if (ext == NULL) { + printf("Filetype not found. Exiting\n"); + exit(-1); + } + else if ((!strcmp((ext + 1), "htm")) || (!strcmp((ext + 1), "html"))) { + return "text/html"; + } + else if (!strcmp((ext + 1), "jpg")) { + return "image/jpeg"; + } + else if (!strcmp((ext + 1), "gif")) { + return "image/gif"; + } + else { + return "text/plain"; + } } // Function to open and read the file from the disk into the memory // Add necessary arguments as needed int readFromDisk(/*necessary arguments*/) { // Open and read the contents of file given the request + } /**********************************************************************************/ @@ -176,7 +193,6 @@ int main(int argc, char **argv) { return -1; } // Initialize cache (extra credit B) - mkdir(cache, 0666); // Start the server init(port); // Create dispatcher threads (make detachable????) -- cgit v1.2.3