enabled the http file handler to accept POST, PUT, DELETE
This commit is contained in:
10
bin/t01.c
10
bin/t01.c
@ -961,7 +961,7 @@ if (hio_htre_getcontentlen(req) > 0)
|
||||
hio_htre_discardcontent (req);
|
||||
/* 411 Length Required - can't keep alive. Force disconnect */
|
||||
req->flags &= ~HIO_HTRE_ATTR_KEEPALIVE; /* to cause sendstatus() to close */
|
||||
if (hio_svc_htts_sendstatus(htts, csck, req, 411, HIO_NULL) <= -1) goto oops;
|
||||
if (hio_svc_htts_sendstatus(htts, csck, req, HIO_HTTP_STATUS_LENGTH_REQUIRED, HIO_NULL) <= -1) goto oops;
|
||||
}
|
||||
else
|
||||
|
||||
@ -970,13 +970,13 @@ if (hio_htre_getcontentlen(req) > 0)
|
||||
const hio_bch_t* qpath = hio_htre_getqpath(req);
|
||||
int x;
|
||||
if (hio_comp_bcstr_limited(qpath, "/thr/", 5, 1) == 0)
|
||||
x = hio_svc_htts_dothr(htts, csck, req, on_htts_thr_request, HIO_NULL);
|
||||
x = hio_svc_htts_dothr(htts, csck, req, on_htts_thr_request, HIO_NULL, 0);
|
||||
else if (hio_comp_bcstr_limited(qpath, "/txt/", 5, 1) == 0)
|
||||
x = hio_svc_htts_dotxt(htts, csck, req, 200, "text/plain", qpath);
|
||||
x = hio_svc_htts_dotxt(htts, csck, req, HIO_HTTP_STATUS_OK, "text/plain", qpath, 0);
|
||||
else if (hio_comp_bcstr_limited(qpath, "/cgi/", 5, 1) == 0)
|
||||
x = hio_svc_htts_docgi(htts, csck, req, "", qpath + 4);
|
||||
x = hio_svc_htts_docgi(htts, csck, req, "", qpath + 4, 0);
|
||||
else
|
||||
x = hio_svc_htts_dofile(htts, csck, req, "", qpath, "text/plain");
|
||||
x = hio_svc_htts_dofile(htts, csck, req, "", qpath, "text/plain", 0);
|
||||
if (x <= -1) goto oops;
|
||||
}
|
||||
#if 0
|
||||
|
20
bin/t06.c
20
bin/t06.c
@ -45,7 +45,7 @@ static void on_htts_thr_request (hio_t* hio, hio_dev_thr_iopair_t* iop, hio_svc_
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf (fp, "Status: 200\r\n");
|
||||
fprintf (fp, "Status: %d\r\n", HIO_HTTP_STATUS_OK);
|
||||
fprintf (fp, "Content-Type: text/html\r\n\r\n");
|
||||
|
||||
fprintf (fp, "request path = %s\n", tfi->req_path);
|
||||
@ -82,13 +82,13 @@ static void on_htts_thr2_request (hio_t* hio, hio_dev_thr_iopair_t* iop, hio_svc
|
||||
sf = fopen(&tfi->req_path[5], "r");
|
||||
if (!sf)
|
||||
{
|
||||
fprintf (fp, "Status: 404\r\n\r\n");
|
||||
fprintf (fp, "Status: %d\r\n\r\n", HIO_HTTP_STATUS_NOT_FOUND);
|
||||
}
|
||||
else
|
||||
{
|
||||
char buf[4096];
|
||||
|
||||
fprintf (fp, "Status: 200\r\n");
|
||||
fprintf (fp, "Status: %d\r\n", HIO_HTTP_STATUS_OK);
|
||||
fprintf (fp, "Content-Type: text/html\r\n\r\n");
|
||||
|
||||
while (!feof(sf) && !ferror(sf))
|
||||
@ -188,7 +188,7 @@ if (hio_htre_getcontentlen(req) > 0)
|
||||
hio_htre_discardcontent (req);
|
||||
/* 411 Length Required - can't keep alive. Force disconnect */
|
||||
req->flags &= ~HIO_HTRE_ATTR_KEEPALIVE; /* to cause sendstatus() to close */
|
||||
if (hio_svc_htts_sendstatus(htts, csck, req, 411, HIO_NULL) <= -1) goto oops;
|
||||
if (hio_svc_htts_sendstatus(htts, csck, req, HIO_HTTP_STATUS_LENGTH_REQUIRED, HIO_NULL) <= -1) goto oops;
|
||||
}
|
||||
else
|
||||
|
||||
@ -197,21 +197,21 @@ if (hio_htre_getcontentlen(req) > 0)
|
||||
const hio_bch_t* qpath = hio_htre_getqpath(req);
|
||||
int x;
|
||||
if (hio_comp_bcstr_limited(qpath, "/thr/", 5, 1) == 0)
|
||||
x = hio_svc_htts_dothr(htts, csck, req, on_htts_thr_request, HIO_NULL);
|
||||
x = hio_svc_htts_dothr(htts, csck, req, on_htts_thr_request, HIO_NULL, HIO_SVC_HTTS_THR_NO_100_CONTINUE);
|
||||
else if (hio_comp_bcstr_limited(qpath, "/thr2/", 6, 1) == 0)
|
||||
x = hio_svc_htts_dothr(htts, csck, req, on_htts_thr2_request, HIO_NULL);
|
||||
x = hio_svc_htts_dothr(htts, csck, req, on_htts_thr2_request, HIO_NULL, HIO_SVC_HTTS_THR_NO_100_CONTINUE);
|
||||
else if (hio_comp_bcstr_limited(qpath, "/txt/", 5, 1) == 0)
|
||||
x = hio_svc_htts_dotxt(htts, csck, req, 200, "text/plain", qpath);
|
||||
x = hio_svc_htts_dotxt(htts, csck, req, HIO_HTTP_STATUS_OK, "text/plain", qpath, 0);
|
||||
else if (hio_comp_bcstr_limited(qpath, "/cgi/", 5, 1) == 0)
|
||||
x = hio_svc_htts_docgi(htts, csck, req, "", qpath + 4);
|
||||
x = hio_svc_htts_docgi(htts, csck, req, "", qpath + 4, 0);
|
||||
else if (hio_comp_bcstr_limited(qpath, "/fcgi/", 5, 1) == 0)
|
||||
{
|
||||
hio_skad_t fcgis_addr;
|
||||
hio_bcstrtoskad(hio, "127.0.0.1:9000", &fcgis_addr);
|
||||
x = hio_svc_htts_dofcgi(htts, csck, req, &fcgis_addr);
|
||||
x = hio_svc_htts_dofcgi(htts, csck, req, &fcgis_addr, 0);
|
||||
}
|
||||
else
|
||||
x = hio_svc_htts_dofile(htts, csck, req, "", qpath, "text/plain");
|
||||
x = hio_svc_htts_dofile(htts, csck, req, "", qpath, "text/plain", 0);
|
||||
if (x <= -1) goto oops;
|
||||
}
|
||||
#if 0
|
||||
|
11
bin/webs.c
11
bin/webs.c
@ -21,21 +21,22 @@ static int process_http_request (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_
|
||||
mth = hio_htre_getqmethodtype(req);
|
||||
qpath = hio_htre_getqpath(req);
|
||||
|
||||
if (mth == HIO_HTTP_GET || mth == HIO_HTTP_POST)
|
||||
|
||||
// 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 */
|
||||
if (hio_svc_htts_dofile(htts, csck, req, ext->docroot, qpath, mt) <= -1) goto oops;
|
||||
if (hio_svc_htts_dofile(htts, csck, req, ext->docroot, qpath, mt, 0) <= -1) goto oops;
|
||||
}
|
||||
#if 0
|
||||
else
|
||||
{
|
||||
if (hio_svc_htts_dotxt(htts, csck, req, 403, "text/plain", hio_http_status_to_bcstr(403)) <= -1) goto oops;
|
||||
if (hio_svc_htts_dotxt(htts, csck, req, HIO_HTTP_STATUS_FORBIDDEN, "text/plain", hio_http_status_to_bcstr(403), 0) <= -1) goto oops;
|
||||
}
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
|
||||
oops:
|
||||
|
Reference in New Issue
Block a user