-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
22 lines (20 loc) · 738 Bytes
/
utils.c
File metadata and controls
22 lines (20 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <string.h>
#include "http.h"
const char *get_mime_type(const char *path){
const char *extension = strrchr(path, '.');
if (!extension) return "application/octet-stream";
if (strcmp(extension,".html") == 0) return "text/html";
if(strcmp(extension, ".css") == 0) return "text/css";
if (strcmp(extension, ".js") == 0) return "application/javascript";
if (strcmp(extension, ".json") == 0) return "application/json";
return "application/octet-stream";
}
int sanitize_uri(char *uri) {
if (uri[0] != '/') return -1;
if (strstr(uri, "..")) return -1;
const char *invalid = "<>\"{}|\\^[]`";
for (int i = 0; uri[i]; i++) {
if (strchr(invalid, uri[i])) return -1;
}
return 0;
}