hio/lib/http-txt.c

391 lines
13 KiB
C
Raw Normal View History

2020-05-26 13:15:25 +00:00
/*
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
2022-06-11 05:32:01 +00:00
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2020-05-26 13:15:25 +00:00
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "http-prv.h"
2021-07-22 07:30:20 +00:00
#include <hio-fmt.h>
#include <hio-chr.h>
2020-05-26 13:15:25 +00:00
2020-11-16 16:52:49 +00:00
#define TXT_OVER_READ_FROM_CLIENT (1 << 0)
#define TXT_OVER_WRITE_TO_CLIENT (1 << 1)
#define TXT_OVER_ALL (TXT_OVER_READ_FROM_CLIENT | TXT_OVER_WRITE_TO_CLIENT)
2020-05-26 13:15:25 +00:00
2020-11-16 16:52:49 +00:00
struct txt_t
2020-05-26 13:15:25 +00:00
{
HIO_SVC_HTTS_TASK_HEADER;
2020-05-26 13:15:25 +00:00
int options;
2021-07-22 07:30:20 +00:00
hio_oow_t num_pending_writes_to_client;
hio_svc_htts_cli_t* client;
hio_http_version_t req_version; /* client request */
2020-05-26 13:15:25 +00:00
2020-11-16 16:52:49 +00:00
unsigned int over: 2; /* must be large enough to accomodate TXT_OVER_ALL */
2020-05-26 13:15:25 +00:00
unsigned int keep_alive: 1;
unsigned int req_content_length_unlimited: 1;
unsigned int client_eof_detected: 1;
2020-05-26 13:15:25 +00:00
unsigned int client_disconnected: 1;
2020-05-26 14:58:55 +00:00
unsigned int client_htrd_recbs_changed: 1;
2021-07-22 07:30:20 +00:00
hio_oow_t req_content_length; /* client request content length */
2020-05-26 13:15:25 +00:00
2021-07-22 07:30:20 +00:00
hio_dev_sck_on_read_t client_org_on_read;
hio_dev_sck_on_write_t client_org_on_write;
hio_dev_sck_on_disconnect_t client_org_on_disconnect;
hio_htrd_recbs_t client_htrd_org_recbs;
2020-05-26 13:15:25 +00:00
};
2020-11-16 16:52:49 +00:00
typedef struct txt_t txt_t;
2020-05-26 13:15:25 +00:00
2020-11-16 16:52:49 +00:00
static void txt_halt_participating_devices (txt_t* txt)
2020-05-26 13:15:25 +00:00
{
2021-07-22 07:30:20 +00:00
HIO_ASSERT (txt->client->htts->hio, txt->client != HIO_NULL);
HIO_ASSERT (txt->client->htts->hio, txt->client->sck != HIO_NULL);
HIO_DEBUG3 (txt->client->htts->hio, "HTTS(%p) - Halting participating devices in txt state %p(client=%p)\n", txt->client->htts, txt, txt->client->sck);
hio_dev_sck_halt (txt->client->sck);
2020-05-26 13:15:25 +00:00
}
2021-07-22 07:30:20 +00:00
static int txt_write_to_client (txt_t* txt, const void* data, hio_iolen_t dlen)
2020-05-26 13:15:25 +00:00
{
2020-11-16 16:52:49 +00:00
txt->num_pending_writes_to_client++;
if (hio_dev_sck_write(txt->client->sck, data, dlen, HIO_NULL, HIO_NULL) <= -1)
2020-05-26 13:15:25 +00:00
{
2020-11-16 16:52:49 +00:00
txt->num_pending_writes_to_client--;
2020-05-26 13:15:25 +00:00
return -1;
}
return 0;
}
2020-05-26 14:58:55 +00:00
#if 0
2021-07-22 07:30:20 +00:00
static int txt_writev_to_client (txt_t* txt, hio_iovec_t* iov, hio_iolen_t iovcnt)
2020-05-26 13:15:25 +00:00
{
2020-11-16 16:52:49 +00:00
txt->num_pending_writes_to_client++;
if (hio_dev_sck_writev(txt->client->sck, iov, iovcnt, HIO_NULL, HIO_NULL) <= -1)
2020-05-26 13:15:25 +00:00
{
2020-11-16 16:52:49 +00:00
txt->num_pending_writes_to_client--;
2020-05-26 13:15:25 +00:00
return -1;
}
return 0;
}
2020-05-26 14:58:55 +00:00
#endif
2020-05-26 13:15:25 +00:00
2020-11-16 16:52:49 +00:00
static int txt_send_final_status_to_client (txt_t* txt, int status_code, const char* content_type, const char* content_text, int force_close)
2020-05-26 13:15:25 +00:00
{
2021-07-22 07:30:20 +00:00
hio_svc_htts_cli_t* cli = txt->client;
hio_bch_t dtbuf[64];
hio_oow_t content_text_len = 0;
2020-05-26 13:15:25 +00:00
2021-07-22 07:30:20 +00:00
hio_svc_htts_fmtgmtime (cli->htts, HIO_NULL, dtbuf, HIO_COUNTOF(dtbuf));
2020-05-26 13:15:25 +00:00
2020-11-16 16:52:49 +00:00
if (!force_close) force_close = !txt->keep_alive;
2020-05-26 14:58:55 +00:00
2021-07-22 07:30:20 +00:00
if (hio_becs_fmt(cli->sbuf, "HTTP/%d.%d %d %hs\r\nServer: %hs\r\nDate: %s\r\nConnection: %hs\r\n",
2020-11-16 16:52:49 +00:00
txt->req_version.major, txt->req_version.minor,
2021-07-22 07:30:20 +00:00
status_code, hio_http_status_to_bcstr(status_code),
2020-05-26 13:15:25 +00:00
cli->htts->server_name, dtbuf,
2020-05-26 14:58:55 +00:00
(force_close? "close": "keep-alive"),
2021-07-22 07:30:20 +00:00
(content_text? hio_count_bcstr(content_text): 0), (content_text? content_text: "")) == (hio_oow_t)-1) return -1;
2020-05-26 13:15:25 +00:00
2020-05-26 14:58:55 +00:00
if (content_text)
2020-05-26 13:15:25 +00:00
{
2021-07-22 07:30:20 +00:00
content_text_len = hio_count_bcstr(content_text);
if (content_type && hio_becs_fcat(cli->sbuf, "Content-Type: %hs\r\n", content_type) == (hio_oow_t)-1) return -1;
2020-05-26 13:15:25 +00:00
}
2021-07-22 07:30:20 +00:00
if (hio_becs_fcat(cli->sbuf, "Content-Length: %zu\r\n\r\n", content_text_len) == (hio_oow_t)-1) return -1;
2020-05-26 13:15:25 +00:00
2021-07-22 07:30:20 +00:00
return (txt_write_to_client(txt, HIO_BECS_PTR(cli->sbuf), HIO_BECS_LEN(cli->sbuf)) <= -1 ||
2020-11-16 16:52:49 +00:00
(content_text && txt_write_to_client(txt, content_text, content_text_len) <= -1) ||
2021-07-22 07:30:20 +00:00
(force_close && txt_write_to_client(txt, HIO_NULL, 0) <= -1))? -1: 0;
2020-05-26 13:15:25 +00:00
}
2021-07-22 07:30:20 +00:00
static HIO_INLINE void txt_mark_over (txt_t* txt, int over_bits)
2020-05-26 13:15:25 +00:00
{
unsigned int old_over;
2020-11-16 16:52:49 +00:00
old_over = txt->over;
txt->over |= over_bits;
2020-05-26 13:15:25 +00:00
2021-07-22 07:30:20 +00:00
HIO_DEBUG4 (txt->htts->hio, "HTTS(%p) - client=%p new-bits=%x over=%x\n", txt->htts, txt->client->sck, (int)over_bits, (int)txt->over);
2020-05-26 13:15:25 +00:00
2020-11-16 16:52:49 +00:00
if (!(old_over & TXT_OVER_READ_FROM_CLIENT) && (txt->over & TXT_OVER_READ_FROM_CLIENT))
2020-05-26 13:15:25 +00:00
{
if (hio_dev_sck_read(txt->client->sck, 0) <= -1)
2020-05-26 13:15:25 +00:00
{
2021-07-22 07:30:20 +00:00
HIO_DEBUG2 (txt->htts->hio, "HTTS(%p) - halting client(%p) for failure to disable input watching\n", txt->htts, txt->client->sck);
hio_dev_sck_halt (txt->client->sck);
2020-05-26 13:15:25 +00:00
}
}
2020-11-16 16:52:49 +00:00
if (old_over != TXT_OVER_ALL && txt->over == TXT_OVER_ALL)
2020-05-26 13:15:25 +00:00
{
/* ready to stop */
if (txt->keep_alive && !txt->client_eof_detected)
2020-05-26 13:15:25 +00:00
{
2020-11-16 16:52:49 +00:00
/* how to arrange to delete this txt object and put the socket back to the normal waiting state??? */
HIO_ASSERT (txt->htts->hio, txt->client->task == (hio_svc_htts_task_t*)txt);
2020-05-26 13:15:25 +00:00
/*printf ("DETACHING FROM THE MAIN CLIENT TASK... state -> %p\n", txt->client->task);*/
HIO_SVC_HTTS_TASK_UNREF (txt->client->task);
2020-11-16 16:52:49 +00:00
/* txt must not be access from here down as it could have been destroyed */
2020-05-26 13:15:25 +00:00
}
else
{
2021-07-22 07:30:20 +00:00
HIO_DEBUG2 (txt->htts->hio, "HTTS(%p) - halting client(%p) for no keep-alive\n", txt->htts, txt->client->sck);
hio_dev_sck_shutdown (txt->client->sck, HIO_DEV_SCK_SHUTDOWN_WRITE);
hio_dev_sck_halt (txt->client->sck);
2020-05-26 13:15:25 +00:00
}
}
}
static void txt_on_kill (hio_svc_htts_task_t* task)
2020-05-26 13:15:25 +00:00
{
txt_t* txt = (txt_t*)task;
2021-07-22 07:30:20 +00:00
hio_t* hio = txt->htts->hio;
2020-07-08 05:24:40 +00:00
2021-07-22 07:30:20 +00:00
HIO_DEBUG2 (hio, "HTTS(%p) - killing txt client(%p)\n", txt->htts, txt->client->sck);
2020-07-08 05:24:40 +00:00
2020-11-16 16:52:49 +00:00
if (txt->client_org_on_read)
2020-05-26 13:15:25 +00:00
{
2020-11-16 16:52:49 +00:00
txt->client->sck->on_read = txt->client_org_on_read;
2021-07-22 07:30:20 +00:00
txt->client_org_on_read = HIO_NULL;
2020-05-26 13:15:25 +00:00
}
2020-11-16 16:52:49 +00:00
if (txt->client_org_on_write)
2020-05-26 13:15:25 +00:00
{
2020-11-16 16:52:49 +00:00
txt->client->sck->on_write = txt->client_org_on_write;
2021-07-22 07:30:20 +00:00
txt->client_org_on_write = HIO_NULL;
2020-05-26 13:15:25 +00:00
}
2020-11-16 16:52:49 +00:00
if (txt->client_org_on_disconnect)
2020-05-26 13:15:25 +00:00
{
2020-11-16 16:52:49 +00:00
txt->client->sck->on_disconnect = txt->client_org_on_disconnect;
2021-07-22 07:30:20 +00:00
txt->client_org_on_disconnect = HIO_NULL;
2020-05-26 13:15:25 +00:00
}
2020-11-16 16:52:49 +00:00
if (txt->client_htrd_recbs_changed)
2020-05-26 14:58:55 +00:00
{
/* restore the callbacks */
hio_htrd_setrecbs (txt->client->htrd, &txt->client_htrd_org_recbs);
2020-05-26 14:58:55 +00:00
}
2020-05-26 13:15:25 +00:00
2020-11-16 16:52:49 +00:00
if (!txt->client_disconnected)
2020-05-26 13:15:25 +00:00
{
2020-11-16 16:52:49 +00:00
/*printf ("ENABLING INPUT WATCHING on CLIENT %p. \n", txt->client->sck);*/
2021-07-22 07:30:20 +00:00
if (!txt->keep_alive || hio_dev_sck_read(txt->client->sck, 1) <= -1)
2020-05-26 13:15:25 +00:00
{
2021-07-22 07:30:20 +00:00
HIO_DEBUG2 (hio, "HTTS(%p) - halting client(%p) for failure to enable input watching\n", txt->htts, txt->client->sck);
hio_dev_sck_halt (txt->client->sck);
2020-05-26 13:15:25 +00:00
}
}
2020-11-16 16:52:49 +00:00
/*printf ("**** TXT_ON_KILL DONE\n");*/
2020-05-26 13:15:25 +00:00
}
2021-07-22 07:30:20 +00:00
static int txt_client_htrd_poke (hio_htrd_t* htrd, hio_htre_t* req)
2020-05-26 13:15:25 +00:00
{
/* client request got completed */
2021-07-22 07:30:20 +00:00
hio_svc_htts_cli_htrd_xtn_t* htrdxtn = (hio_svc_htts_cli_htrd_xtn_t*)hio_htrd_getxtn(htrd);
hio_dev_sck_t* sck = htrdxtn->sck;
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(sck);
txt_t* txt = (txt_t*)cli->task;
2020-05-26 13:15:25 +00:00
/*printf (">> CLIENT REQUEST COMPLETED\n");*/
2020-05-26 13:15:25 +00:00
2020-11-16 16:52:49 +00:00
txt_mark_over (txt, TXT_OVER_READ_FROM_CLIENT);
2020-05-26 13:15:25 +00:00
return 0;
}
2021-07-22 07:30:20 +00:00
static int txt_client_htrd_push_content (hio_htrd_t* htrd, hio_htre_t* req, const hio_bch_t* data, hio_oow_t dlen)
2020-05-26 13:15:25 +00:00
{
2020-05-26 14:58:55 +00:00
/* discard all contents */
2020-05-26 13:15:25 +00:00
return 0;
}
2021-07-22 07:30:20 +00:00
static hio_htrd_recbs_t txt_client_htrd_recbs =
2020-05-26 13:15:25 +00:00
{
2021-07-22 07:30:20 +00:00
HIO_NULL,
2020-05-26 13:15:25 +00:00
txt_client_htrd_poke,
txt_client_htrd_push_content
};
2021-07-22 07:30:20 +00:00
static void txt_client_on_disconnect (hio_dev_sck_t* sck)
2020-05-26 13:15:25 +00:00
{
2021-07-22 07:30:20 +00:00
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(sck);
txt_t* txt = (txt_t*)cli->task;
2020-11-16 16:52:49 +00:00
txt->client_disconnected = 1;
txt->client_org_on_disconnect (sck);
2020-05-26 13:15:25 +00:00
}
2021-07-22 07:30:20 +00:00
static int txt_client_on_read (hio_dev_sck_t* sck, const void* buf, hio_iolen_t len, const hio_skad_t* srcaddr)
2020-05-26 13:15:25 +00:00
{
2021-07-22 07:30:20 +00:00
hio_t* hio = sck->hio;
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(sck);
txt_t* txt = (txt_t*)cli->task;
2020-05-26 13:15:25 +00:00
2021-07-22 07:30:20 +00:00
HIO_ASSERT (hio, sck == cli->sck);
2020-05-26 13:15:25 +00:00
if (len <= -1)
{
/* read error */
2021-07-22 07:30:20 +00:00
HIO_DEBUG2 (cli->htts->hio, "HTTPS(%p) - read error on client %p(%d)\n", sck, (int)sck->hnd);
2020-05-26 13:15:25 +00:00
goto oops;
}
if (len == 0)
{
/* EOF on the client side. arrange to close */
2021-07-22 07:30:20 +00:00
HIO_DEBUG3 (hio, "HTTPS(%p) - EOF from client %p(hnd=%d)\n", txt->client->htts, sck, (int)sck->hnd);
txt->client_eof_detected = 1;
2020-11-16 16:52:49 +00:00
if (!(txt->over & TXT_OVER_READ_FROM_CLIENT)) /* if this is true, EOF is received without txt_client_htrd_poke() */
2020-05-26 13:15:25 +00:00
{
2020-11-16 16:52:49 +00:00
txt_mark_over (txt, TXT_OVER_READ_FROM_CLIENT);
2020-05-26 13:15:25 +00:00
}
}
else
{
2021-07-22 07:30:20 +00:00
hio_oow_t rem;
2020-05-26 13:15:25 +00:00
2021-07-22 07:30:20 +00:00
HIO_ASSERT (hio, !(txt->over & TXT_OVER_READ_FROM_CLIENT));
2020-05-26 13:15:25 +00:00
2021-07-22 07:30:20 +00:00
if (hio_htrd_feed(cli->htrd, buf, len, &rem) <= -1) goto oops;
2020-05-26 13:15:25 +00:00
if (rem > 0)
{
/* TODO store this to client buffer. once the current resource is completed, arrange to call on_read() with it */
/*printf ("UUUUUUUUUUUUUUUUUUUUUUUUUUGGGGGHHHHHHHHHHHH .......... TXT CLIENT GIVING EXCESSIVE DATA AFTER CONTENTS...\n");*/
2020-05-26 13:15:25 +00:00
}
}
return 0;
oops:
2020-11-16 16:52:49 +00:00
txt_halt_participating_devices (txt);
2020-05-26 13:15:25 +00:00
return 0;
}
2021-07-22 07:30:20 +00:00
static int txt_client_on_write (hio_dev_sck_t* sck, hio_iolen_t wrlen, void* wrctx, const hio_skad_t* dstaddr)
2020-05-26 13:15:25 +00:00
{
2021-07-22 07:30:20 +00:00
hio_t* hio = sck->hio;
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(sck);
txt_t* txt = (txt_t*)cli->task;
2020-05-26 13:15:25 +00:00
if (wrlen <= -1)
{
2021-07-22 07:30:20 +00:00
HIO_DEBUG3 (hio, "HTTPS(%p) - unable to write to client %p(%d)\n", sck->hio, sck, (int)sck->hnd);
2020-05-26 13:15:25 +00:00
goto oops;
}
if (wrlen == 0)
{
/* if the connect is keep-alive, this part may not be called */
2020-11-16 16:52:49 +00:00
txt->num_pending_writes_to_client--;
2021-07-22 07:30:20 +00:00
HIO_ASSERT (hio, txt->num_pending_writes_to_client == 0);
HIO_DEBUG3 (hio, "HTTS(%p) - indicated EOF to client %p(%d)\n", txt->client->htts, sck, (int)sck->hnd);
2020-05-26 13:15:25 +00:00
/* since EOF has been indicated to the client, it must not write to the client any further.
* this also means that i don't need any data from the peer side either.
* i don't need to enable input watching on the peer side */
2020-11-16 16:52:49 +00:00
txt_mark_over (txt, TXT_OVER_WRITE_TO_CLIENT);
2020-05-26 13:15:25 +00:00
}
else
{
2021-07-22 07:30:20 +00:00
HIO_ASSERT (hio, txt->num_pending_writes_to_client > 0);
2020-11-16 16:52:49 +00:00
txt->num_pending_writes_to_client--;
if (txt->num_pending_writes_to_client <= 0)
2020-05-26 13:15:25 +00:00
{
2020-11-16 16:52:49 +00:00
txt_mark_over (txt, TXT_OVER_WRITE_TO_CLIENT);
2020-05-26 13:15:25 +00:00
}
}
return 0;
oops:
2020-11-16 16:52:49 +00:00
txt_halt_participating_devices (txt);
2020-05-26 13:15:25 +00:00
return 0;
}
int hio_svc_htts_dotxt (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* req, int status_code, const hio_bch_t* content_type, const hio_bch_t* content_text, int options)
2020-05-26 13:15:25 +00:00
{
2021-07-22 07:30:20 +00:00
hio_t* hio = htts->hio;
hio_svc_htts_cli_t* cli = hio_dev_sck_getxtn(csck);
txt_t* txt = HIO_NULL;
2020-05-26 13:15:25 +00:00
/* ensure that you call this function before any contents is received */
2021-07-22 07:30:20 +00:00
HIO_ASSERT (hio, hio_htre_getcontentlen(req) == 0);
2020-05-26 13:15:25 +00:00
txt = (txt_t*)hio_svc_htts_task_make(htts, HIO_SIZEOF(*txt), txt_on_kill);
2021-07-22 07:30:20 +00:00
if (HIO_UNLIKELY(!txt)) goto oops;
2020-05-26 13:15:25 +00:00
txt->options = options;
2020-11-16 16:52:49 +00:00
txt->client = cli;
/*txt->num_pending_writes_to_client = 0;*/
2021-07-22 07:30:20 +00:00
txt->req_version = *hio_htre_getversion(req);
txt->req_content_length_unlimited = hio_htre_getreqcontentlen(req, &txt->req_content_length);
2020-05-26 13:15:25 +00:00
2020-11-16 16:52:49 +00:00
txt->client_org_on_read = csck->on_read;
txt->client_org_on_write = csck->on_write;
txt->client_org_on_disconnect = csck->on_disconnect;
2020-05-26 13:15:25 +00:00
csck->on_read = txt_client_on_read;
csck->on_write = txt_client_on_write;
csck->on_disconnect = txt_client_on_disconnect;
HIO_ASSERT (hio, cli->task == HIO_NULL);
HIO_SVC_HTTS_TASK_REF ((hio_svc_htts_task_t*)txt, cli->task);
2020-05-26 13:15:25 +00:00
2021-07-22 07:30:20 +00:00
if (req->flags & HIO_HTRE_ATTR_EXPECT100)
2020-05-26 13:15:25 +00:00
{
2020-05-26 14:58:55 +00:00
/* don't send 100-Continue. If the client posts data regardless, ignore them later */
2020-05-26 13:15:25 +00:00
}
2021-07-22 07:30:20 +00:00
else if (req->flags & HIO_HTRE_ATTR_EXPECT)
2020-05-26 13:15:25 +00:00
{
/* 417 Expectation Failed */
txt_send_final_status_to_client(txt, HIO_HTTP_STATUS_EXPECTATION_FAILED, HIO_NULL, HIO_NULL, 1);
2020-05-26 13:15:25 +00:00
goto oops;
}
2020-11-16 16:52:49 +00:00
if (txt->req_content_length_unlimited || txt->req_content_length > 0)
2020-05-26 13:15:25 +00:00
{
/* change the callbacks to subscribe to contents to be uploaded */
2021-07-22 07:30:20 +00:00
txt->client_htrd_org_recbs = *hio_htrd_getrecbs(txt->client->htrd);
2020-11-16 16:52:49 +00:00
txt_client_htrd_recbs.peek = txt->client_htrd_org_recbs.peek;
2021-07-22 07:30:20 +00:00
hio_htrd_setrecbs (txt->client->htrd, &txt_client_htrd_recbs);
2020-11-16 16:52:49 +00:00
txt->client_htrd_recbs_changed = 1;
2020-05-26 13:15:25 +00:00
}
else
{
2020-05-26 14:58:55 +00:00
/* no content to be uploaded from the client */
/* indicate EOF to the peer and disable input wathching from the client */
2020-11-16 16:52:49 +00:00
txt_mark_over (txt, TXT_OVER_READ_FROM_CLIENT);
2020-05-26 13:15:25 +00:00
}
/* this may change later if Content-Length is included in the txt output */
2021-07-22 07:30:20 +00:00
txt->keep_alive = !!(req->flags & HIO_HTRE_ATTR_KEEPALIVE);
2020-05-26 13:15:25 +00:00
2020-11-16 16:52:49 +00:00
/* TODO: store current input watching state and use it when destroying the txt data */
2021-07-22 07:30:20 +00:00
if (hio_dev_sck_read(csck, !(txt->over & TXT_OVER_READ_FROM_CLIENT)) <= -1) goto oops;
2020-05-26 14:58:55 +00:00
2020-11-16 16:52:49 +00:00
if (txt_send_final_status_to_client(txt, status_code, content_type, content_text, 0) <= -1) goto oops;
2020-05-26 13:15:25 +00:00
return 0;
oops:
2021-07-22 07:30:20 +00:00
HIO_DEBUG2 (hio, "HTTS(%p) - FAILURE in dotxt - socket(%p)\n", htts, csck);
2020-11-16 16:52:49 +00:00
if (txt) txt_halt_participating_devices (txt);
2020-05-26 13:15:25 +00:00
return -1;
}