diff --git a/bin/webs.c b/bin/webs.c index 0344583..08cb3fa 100644 --- a/bin/webs.c +++ b/bin/webs.c @@ -79,16 +79,16 @@ static int process_http_request (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_ if (mth == HIO_HTTP_OTHER && hio_comp_bcstr(hio_htre_getqmethodname(req), "UNTAR", 1) == 0) { + /* don't care about the path for now. TODO: make this secure and reasonable */ hio_svc_htts_dothr(htts, csck, req, untar, HIO_NULL, 0); } - else -// if (mth == HIO_HTTP_GET || mth == HIO_HTTP_POST) + else // if (mth == HIO_HTTP_GET || mth == HIO_HTTP_POST) { /* TODO: proper mime-type */ const hio_bch_t* dot; hio_bch_t mt[128]; dot = hio_rfind_bchar_in_bcstr(qpath, '.'); - hio_fmttobcstr (hio, mt, HIO_COUNTOF(mt), "text/%hs", ((dot && dot[1] != '\0')? &dot[1]: "plain")); /* TODO: error check */ + hio_fmttobcstr (hio, mt, HIO_COUNTOF(mt), "text/%hs", ((dot && dot[1] != '\0')? &dot[1]: "html")); /* TODO: error check */ if (hio_svc_htts_dofile(htts, csck, req, ext->docroot, qpath, mt, 0) <= -1) goto oops; } #if 0 diff --git a/lib/http-file.c b/lib/http-file.c index 3ca2b0e..d707910 100644 --- a/lib/http-file.c +++ b/lib/http-file.c @@ -674,6 +674,8 @@ static HIO_INLINE int process_range_header (file_t* file, hio_htre_t* req, int* static int open_peer_with_mode (file_t* file, const hio_bch_t* actual_file, int flags, int* error_status) { + struct stat st; + flags |= O_NONBLOCK; #if defined(O_CLOEXEC) flags |= O_CLOEXEC; @@ -689,6 +691,24 @@ static int open_peer_with_mode (file_t* file, const hio_bch_t* actual_file, int return -1; } + if (fstat(file->peer, &st) >= 0 && S_ISDIR(st.st_mode)) + { + hio_bch_t* alt_file; + int alt_fd; + +/* TODO: create an option to support directory listing */ + alt_file = hio_svc_htts_dupmergepaths(file->htts, actual_file, "index.html"); /* TODO: make the default index files configurable */ + if (alt_file) + { + alt_fd = open(alt_file, flags, 0644); + hio_freemem (file->htts->hio, alt_file); + if (alt_fd >= 0) + { + close (file->peer); + file->peer = alt_fd; + } + } + } return 0; }