Fri, 13 May 2022 21:24:45 +0200
add missing HttpStream initializations
add some verbose logging to catch a bug
--- a/src/server/daemon/httprequest.c Wed May 11 20:41:39 2022 +0200 +++ b/src/server/daemon/httprequest.c Fri May 13 21:24:45 2022 +0200 @@ -379,6 +379,7 @@ if(util_strtoint(ctlen_str, &ctlen)) { netbuf *nb = sn->netbuf; HttpStream *net_io = (HttpStream*)sn->sn.csd; + net_io->read_eof = WS_FALSE; // how many bytes are already read and in the buffer int cur_input_available = nb->cursize - nb->pos; @@ -567,6 +568,18 @@ int nsapi_finish_request(NSAPISession *sn, NSAPIRequest *rq) { request_free_resources(sn, rq); + WSBool read_stream_eof = httpstream_eof(sn->sn.csd); + if(!read_stream_eof) { + log_ereport(LOG_WARN, "request input stream not closed"); + // TODO: clean stream + rq->rq.rq_attr.keep_alive = 0; // workaround + } + if(sn->pos < sn->cursize) { + log_ereport(LOG_WARN, "nsapi_finish_request: TODO: remaining bytes in buffer"); + // TODO: reuse buffer in next request + rq->rq.rq_attr.keep_alive = 0; // workaround + } + if(rq->rq.rq_attr.keep_alive) { SessionHandler *sh = sn->connection->session_handler; sh->keep_alive(sh, sn->connection);
--- a/src/server/daemon/sessionhandler.c Wed May 11 20:41:39 2022 +0200 +++ b/src/server/daemon/sessionhandler.c Fri May 13 21:24:45 2022 +0200 @@ -351,6 +351,9 @@ if(state == 2) { // parse error fatal_error(request, 400); + log_ereport(LOG_VERBOSE, "http parser: bad request"); + //printf("\n\n%.*s\n\n", parser->request->netbuf->cursize, parser->request->netbuf->inbuf); + //fflush(stdout); event->finish = evt_request_error; io->error = 2; return 0;
--- a/src/server/util/io.c Wed May 11 20:41:39 2022 +0200 +++ b/src/server/util/io.c Fri May 13 21:24:45 2022 +0200 @@ -252,8 +252,14 @@ st->fd = fd; st->max_read = 0; st->read = 0; + st->read_total = 0; + st->readbuf = NULL; + st->bufsize = 0; + st->buflen = NULL; + st->bufpos = NULL; + st->chunk_buf_pos = 0; st->chunked_enc = WS_FALSE; - st->chunk_buf_pos = 0; + st->read_eof = WS_TRUE; return (IOStream*)st; } @@ -271,6 +277,7 @@ http->buflen = cursize; http->bufpos = pos; http->chunk_buf_pos = 0; + http->read_eof = WS_FALSE; return 0; } @@ -294,6 +301,11 @@ return 0; } +WSBool httpstream_eof(IOStream *st) { + HttpStream *http = (HttpStream*)st; + return http->read_eof; +} + ssize_t net_http_write(HttpStream *st, void *buf, size_t nbytes) { IOStream *fd = st->fd; if(st->chunked_enc) { @@ -342,6 +354,7 @@ ssize_t net_http_read(HttpStream *st, void *buf, size_t nbytes) { if(st->read >= st->max_read) { + st->read_eof = WS_TRUE; return 0; } ssize_t r = st->fd->read(st->fd, buf, nbytes);
--- a/src/server/util/io.h Wed May 11 20:41:39 2022 +0200 +++ b/src/server/util/io.h Fri May 13 21:24:45 2022 +0200 @@ -165,6 +165,7 @@ int httpstream_enable_chunked_read(IOStream *st, char *buffer, size_t bufsize, int *cursize, int *pos); int httpstream_enable_chunked_write(IOStream *st); int httpstream_set_max_read(IOStream *st, int64_t maxread); +WSBool httpstream_eof(IOStream *st); ssize_t net_http_write(HttpStream *st, void *buf, size_t nbytes); ssize_t net_http_writev(HttpStream *st, struct iovec *iovec, int iovcnt);