Sun, 15 May 2022 08:56:00 +0200
make sure the http stream is finished if headers are sent
--- a/src/server/daemon/httprequest.c Sat May 14 15:22:37 2022 +0200 +++ b/src/server/daemon/httprequest.c Sun May 15 08:56:00 2022 +0200 @@ -579,7 +579,12 @@ // TODO: reuse buffer in next request rq->rq.rq_attr.keep_alive = 0; // workaround } - if(!rq->rq.senthdrs) { + + if(rq->rq.senthdrs) { + // flush buffer and add termination if chunked encoding + // is enabled + net_finish(sn->sn.csd); + } else { // why was no response sent? // something must have gone wrong // terminate the session @@ -898,18 +903,12 @@ } if(ret != REQ_NOACTION) { - if(ret == REQ_PROCEED) { - if(rq->rq.senthdrs) { - // flush buffer and add termination if chunked encoding - // is enabled - net_finish(sn->sn.csd); - } else { - // a service SAF must send a response - // senthdrs == 0 indicators something has gone - // wrong - protocol_status(&sn->sn, &rq->rq, 500, NULL); - ret = REQ_ABORTED; - } + if(ret == REQ_PROCEED && !rq->rq.senthdrs) { + // a service SAF must send a response + // senthdrs == 0 indicators something has gone + // wrong + protocol_status(&sn->sn, &rq->rq, 500, NULL); + ret = REQ_ABORTED; } else if(ret == REQ_PROCESSING) { // save nsapi context rq->context.objset_index = i;
--- a/src/server/util/io.c Sat May 14 15:22:37 2022 +0200 +++ b/src/server/util/io.c Sun May 15 08:56:00 2022 +0200 @@ -260,6 +260,7 @@ st->chunk_buf_pos = 0; st->chunked_enc = WS_FALSE; st->read_eof = WS_TRUE; + st->write_eof = WS_FALSE; return (IOStream*)st; } @@ -307,6 +308,7 @@ } ssize_t net_http_write(HttpStream *st, void *buf, size_t nbytes) { + if(st->write_eof) return 0; IOStream *fd = st->fd; if(st->chunked_enc) { // TODO: on some plattforms iov_len is smaller than size_t @@ -328,6 +330,7 @@ } ssize_t net_http_writev(HttpStream *st, struct iovec *iovec, int iovcnt) { + if(st->write_eof) return 0; IOStream *fd = st->fd; if(st->chunked_enc) { struct iovec *io = calloc(iovcnt + 1, sizeof(struct iovec)); @@ -582,7 +585,8 @@ return rd; } -ssize_t net_http_sendfile(HttpStream *st, sendfiledata *sfd) { +ssize_t net_http_sendfile(HttpStream *st, sendfiledata *sfd) { + if(st->write_eof) return 0; ssize_t ret = 0; // TODO: support chunked transfer encoding if(st->fd->sendfile) { @@ -599,9 +603,10 @@ } void net_http_finish(HttpStream *st) { - if(st->chunked_enc) { + if(st->chunked_enc && !st->write_eof) { st->fd->write(st->fd, "0\r\n\r\n", 5); } + st->write_eof = WS_TRUE; } void net_http_setmode(HttpStream *st, int mode) {