139 LOG_MISCONFIG, |
139 LOG_MISCONFIG, |
140 "find-index: no files specified in index-names parameter"); |
140 "find-index: no files specified in index-names parameter"); |
141 return REQ_ABORTED; |
141 return REQ_ABORTED; |
142 } |
142 } |
143 |
143 |
|
144 // only find index for GET requests |
|
145 // maybe we want to support find-index for other methods, in that case |
|
146 // we should implement a parameter for this |
|
147 char *method = pblock_findkeyval(pb_key_method, rq->reqpb); |
|
148 if(strcmp(method, "GET")) { |
|
149 return REQ_NOACTION; |
|
150 } |
|
151 |
|
152 VFSContext *vfs = vfs_request_context(sn, rq); |
144 int ret = REQ_NOACTION; |
153 int ret = REQ_NOACTION; |
145 |
154 |
146 char *path = pblock_findkeyval(pb_key_path, rq->vars); |
155 char *path = pblock_findkeyval(pb_key_path, rq->vars); |
147 size_t pathlen = strlen(path); |
156 size_t pathlen = strlen(path); |
148 sstr_t p = sstrn(path, pathlen); |
157 sstr_t p = sstrn(path, pathlen); |
149 if(path[pathlen-1] == '/') { |
158 if(path[pathlen-1] == '/') { |
150 for(int i=0;i<ni;i++) { |
159 for(int i=0;i<ni;i++) { |
151 sstr_t newpath = sstrcat(2, p, sstrtrim(names[i])); |
160 sstr_t newpath = sstrcat(2, p, sstrtrim(names[i])); |
152 struct stat s; |
161 struct stat s; |
153 if(!stat(newpath.ptr, &s)) { |
162 if(!vfs_stat(vfs, newpath.ptr, &s)) { |
154 pblock_kvinsert( |
163 pblock_kvinsert( |
155 pb_key_path, |
164 pb_key_path, |
156 newpath.ptr, |
165 newpath.ptr, |
157 newpath.length, |
166 newpath.length, |
158 rq->vars); |
167 rq->vars); |