- /* is a directory */
- else if ((p.stat.st_mode & S_IFDIR) && !strlen(path_info)) {
- /* ensure trailing slash */
- if (path_phys[strlen(path_phys)-1] != '/')
- path_phys[strlen(path_phys)] = '/';
-
- /* try to locate index file */
- memset(buffer, 0, sizeof(buffer));
- memcpy(buffer, path_phys, sizeof(buffer));
- pathptr = &buffer[strlen(buffer)];
-
- /* if requested url resolves to a directory and a trailing slash
- is missing in the request url, redirect the client to the same
- url with trailing slash appended */
- if (!slash) {
- uh_http_header(cl, 302, "Found");
- ustream_printf(cl->us, "Location: %s%s%s\r\n\r\n",
- &path_phys[strlen(docroot)],
- p.query ? "?" : "",
- p.query ? p.query : "");
- uh_request_done(cl);
- p.redirected = 1;
- } else {
- list_for_each_entry(idx, &index_files, list) {
- strncat(buffer, idx->name, sizeof(buffer));
-
- if (!stat(buffer, &s) && (s.st_mode & S_IFREG)) {
- memcpy(path_phys, buffer, sizeof(path_phys));
- memcpy(&p.stat, &s, sizeof(p.stat));
- break;
- }
-
- *pathptr = 0;
- }
- }