1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #include <ucx/string.h>
30 #include <ucx/map.h>
31
32 #include "objecttype.h"
33 #include "../util/pblock.h"
34
35 #include "../daemon/config.h"
36 #include "../daemon/session.h"
37
38 int object_type_by_extension(pblock *pb, Session *sn, Request *rq) {
39 sstr_t path = sstr(pblock_findkeyval(pb_key_path, rq->vars));
40
41
42 sstr_t ct;
43 if(path.ptr[path.length -
1] ==
'/') {
44
45 ct = sstrn(
"internal/directory",
18);
46 }
else {
47 sstr_t ext;
48 ext.length =
0;
49 for(
int i=path.length -
1;i>=
0;i--) {
50 if(path.ptr[i] ==
'.') {
51 ext.ptr = path.ptr + i +
1;
52 ext.length = path.length - i -
1;
53 break;
54 }
55 }
56
57 if(ext.length ==
0) {
58
59 return REQ_NOACTION;
60 }
61
62
63 ServerConfiguration *config = session_get_config(sn);
64
65 WS_ASSERT(config);
66 WS_ASSERT(config->mimetypes);
67 WS_ASSERT(config->mimetypes->map);
68
69 char *type = ucx_map_sstr_get(config->mimetypes->map, ext);
70
71 if(!type) {
72 return REQ_NOACTION;
73 }
74
75 ct.ptr = type;
76 ct.length = strlen(type);
77 }
78
79 pblock_kvinsert(pb_key_content_type, ct.ptr, ct.length, rq->srvhdrs);
80 return REQ_PROCEED;
81 }
82