59 // vfs_open sets http status code |
59 // vfs_open sets http status code |
60 return NULL; |
60 return NULL; |
61 } |
61 } |
62 |
62 |
63 /* get stat */ |
63 /* get stat */ |
64 if (vfs_fstat(vfs, fd, s) != 0) { |
64 if(vfs_fstat(vfs, fd, s) != 0) { |
65 //perror("prepare_service_file: stat"); |
65 //perror("prepare_service_file: stat"); |
66 protocol_status(sn, rq, 500, NULL); |
66 protocol_status(sn, rq, 500, NULL); |
67 return NULL; |
67 return NULL; |
|
68 } |
|
69 |
|
70 // check if the file is a directory |
|
71 if(S_ISDIR(s->st_mode)) { |
|
72 pblock_nvinsert("content-length", "0", rq->srvhdrs); |
|
73 pblock_removekey(pb_key_content_type, rq->srvhdrs); |
|
74 char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); |
|
75 size_t urilen = strlen(uri); |
|
76 char *location = pool_malloc(sn->pool, urilen + 2); |
|
77 memcpy(location, uri, urilen); |
|
78 location[urilen] = '/'; |
|
79 location[urilen+1] = '\0'; |
|
80 pblock_kvinsert(pb_key_location, location, urilen + 1, rq->srvhdrs); |
|
81 protocol_status(sn, rq, 302, NULL); |
|
82 http_start_response(sn, rq); |
|
83 vfs_close(fd); |
|
84 return fd; |
68 } |
85 } |
69 |
86 |
70 /* add content-length header*/ |
87 /* add content-length header*/ |
71 char contentLength[32]; |
88 char contentLength[32]; |
72 int len = snprintf(contentLength, 32, "%d", s->st_size); |
89 int len = snprintf(contentLength, 32, "%d", s->st_size); |