X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-hreq.c;h=badddd1e812045e971210995b7b71e123805815c;hb=8d036c20b1e6e6134817bfc4cb152e4e2469dba5;hp=8928266e0cb548906edd073bac019fb1eb6720f1;hpb=ff24b370ba3f32959068b0cf3b2492e81cf58dda;p=src%2Fapp-framework-binder.git diff --git a/src/afb-hreq.c b/src/afb-hreq.c index 8928266e..badddd1e 100644 --- a/src/afb-hreq.c +++ b/src/afb-hreq.c @@ -312,15 +312,24 @@ int afb_hreq_reply_file_if_exist(struct afb_hreq *hreq, int dirfd, const char *f /* serve directory */ if (S_ISDIR(st.st_mode)) { - if (hreq->url[hreq->lenurl - 1] != '/') { - /* the redirect is needed for reliability of relative path */ - char *tourl = alloca(hreq->lenurl + 2); - memcpy(tourl, hreq->url, hreq->lenurl); - tourl[hreq->lenurl] = '/'; - tourl[hreq->lenurl + 1] = 0; - rc = afb_hreq_redirect_to(hreq, tourl); - } else { - rc = afb_hreq_reply_file_if_exist(hreq, fd, "index.html"); + static const char *indexes[] = { "index.html", NULL }; + int i = 0; + rc = 0; + while (indexes[i] != NULL) { + if (faccessat(fd, indexes[i], R_OK, 0) == 0) { + if (hreq->url[hreq->lenurl - 1] != '/') { + /* the redirect is needed for reliability of relative path */ + char *tourl = alloca(hreq->lenurl + 2); + memcpy(tourl, hreq->url, hreq->lenurl); + tourl[hreq->lenurl] = '/'; + tourl[hreq->lenurl + 1] = 0; + rc = afb_hreq_redirect_to(hreq, tourl); + } else { + rc = afb_hreq_reply_file_if_exist(hreq, fd, indexes[i]); + } + break; + } + i++; } close(fd); return rc;