aboutsummaryrefslogtreecommitdiffstats
path: root/P3
diff options
context:
space:
mode:
authorAndrea Smith <smit9523@umn.edu>2020-11-15 15:02:01 -0600
committerAndrea Smith <smit9523@umn.edu>2020-11-15 15:02:01 -0600
commit5c451db7e75181aae3f7b2f48406b28e7bba7c77 (patch)
tree42873554bf58d24c6d9d75c903e068ee44fa21a3 /P3
parenthelp (diff)
downloadcsci4061-5c451db7e75181aae3f7b2f48406b28e7bba7c77.tar
csci4061-5c451db7e75181aae3f7b2f48406b28e7bba7c77.tar.gz
csci4061-5c451db7e75181aae3f7b2f48406b28e7bba7c77.tar.bz2
csci4061-5c451db7e75181aae3f7b2f48406b28e7bba7c77.tar.lz
csci4061-5c451db7e75181aae3f7b2f48406b28e7bba7c77.tar.xz
csci4061-5c451db7e75181aae3f7b2f48406b28e7bba7c77.tar.zst
csci4061-5c451db7e75181aae3f7b2f48406b28e7bba7c77.zip
Added getContentType
Diffstat (limited to 'P3')
-rw-r--r--P3/server.c20
1 files changed, 18 insertions, 2 deletions
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????)