changed hio_svc_htts_dofile() to attempt index.html if a directory is given
This commit is contained in:
parent
c608ae9246
commit
1ba44dc203
@ -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)
|
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);
|
hio_svc_htts_dothr(htts, csck, req, untar, HIO_NULL, 0);
|
||||||
}
|
}
|
||||||
else
|
else // if (mth == HIO_HTTP_GET || mth == HIO_HTTP_POST)
|
||||||
// if (mth == HIO_HTTP_GET || mth == HIO_HTTP_POST)
|
|
||||||
{
|
{
|
||||||
/* TODO: proper mime-type */
|
/* TODO: proper mime-type */
|
||||||
const hio_bch_t* dot;
|
const hio_bch_t* dot;
|
||||||
hio_bch_t mt[128];
|
hio_bch_t mt[128];
|
||||||
dot = hio_rfind_bchar_in_bcstr(qpath, '.');
|
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 (hio_svc_htts_dofile(htts, csck, req, ext->docroot, qpath, mt, 0) <= -1) goto oops;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
|
@ -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)
|
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;
|
flags |= O_NONBLOCK;
|
||||||
#if defined(O_CLOEXEC)
|
#if defined(O_CLOEXEC)
|
||||||
flags |= 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;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user