fixed more issue in multiple http task handlers

This commit is contained in:
2023-01-15 00:59:43 +09:00
parent f03453c21b
commit a7dde21b4d
6 changed files with 162 additions and 120 deletions

View File

@ -146,18 +146,24 @@ static int file_send_final_status_to_client (file_t* file, int status_code, int
hio_svc_htts_cli_t* cli = file->client;
hio_bch_t dtbuf[64];
const hio_bch_t* status_msg;
hio_oow_t content_len;
hio_svc_htts_fmtgmtime (cli->htts, HIO_NULL, dtbuf, HIO_COUNTOF(dtbuf));
status_msg = hio_http_status_to_bcstr(status_code);
content_len = hio_count_bcstr(status_msg);
if (!force_close) force_close = !file->keep_alive;
if (hio_becs_fmt(cli->sbuf, "HTTP/%d.%d %d %hs\r\nServer: %hs\r\nDate: %s\r\nConnection: %hs\r\n",
if (hio_becs_fmt(cli->sbuf, "HTTP/%d.%d %d %hs\r\nServer: %hs\r\nDate: %hs\r\nConnection: %hs\r\n",
file->req_version.major, file->req_version.minor,
status_code, status_msg,
cli->htts->server_name, dtbuf,
(force_close? "close": "keep-alive")) == (hio_oow_t)-1) return -1;
if (file->req_method == HIO_HTTP_HEAD && status_code != HIO_HTTP_STATUS_OK) status_msg = "";
if (file->req_method == HIO_HTTP_HEAD)
{
if (status_code != HIO_HTTP_STATUS_OK) content_len = 0;
status_msg = "";
}
if (dir_redirect)
{
@ -166,7 +172,7 @@ static int file_send_final_status_to_client (file_t* file, int status_code, int
}
else
{
if (hio_becs_fcat(cli->sbuf, "Content-Type: text/plain\r\nContent-Length: %zu\r\n\r\n%hs", hio_count_bcstr(status_msg), status_msg) == (hio_oow_t)-1) return -1;
if (hio_becs_fcat(cli->sbuf, "Content-Type: text/plain\r\nContent-Length: %zu\r\n\r\n%hs", content_len, status_msg) == (hio_oow_t)-1) return -1;
}
return (file_write_to_client(file, HIO_BECS_PTR(cli->sbuf), HIO_BECS_LEN(cli->sbuf)) <= -1 ||