From a3542afd311cfaa9eebdf14dbcab108ac112b14f Mon Sep 17 00:00:00 2001 From: Jan Kneschke Date: Thu, 21 Sep 2006 12:51:14 +0000 Subject: [PATCH] handle connection-close after after a broken header in keep-alive like {{{ GET / HTTP/1.1 Host: foo GET }}} git-svn-id: svn://svn.lighttpd.net/lighttpd/branches/lighttpd-1.4.11-ssl-fixes@1328 152afb58-edef-0310-8abb-c4023f1b3aa9 --- src/connections.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/connections.c b/src/connections.c index 7aab9088..5c94d15d 100644 --- a/src/connections.c +++ b/src/connections.c @@ -216,7 +216,7 @@ static int connection_handle_read_ssl(server *srv, connection *con) { if (len > 0) { b->used = len; b->ptr[b->used++] = '\0'; - + /* we move the buffer to the chunk-queue, no need to free it */ chunkqueue_append_buffer_weak(con->read_queue, b); @@ -839,6 +839,7 @@ int connection_handle_read_state(server *srv, connection *con) { off_t last_offset; chunkqueue *cq = con->read_queue; chunkqueue *dst_cq = con->request_content_queue; + int is_closed = 0; /* the connection got closed, if we don't have a complete header, -> error */ if (con->is_readable) { con->read_idle_ts = srv->cur_ts; @@ -847,15 +848,8 @@ int connection_handle_read_state(server *srv, connection *con) { case -1: return -1; case -2: - /* remote side closed the connection - * if we still have content, handle it, if not leave here */ - - if (cq->first == cq->last && - (!cq->first || cq->first->mem->used == 0)) { - - /* conn-closed, leave here */ - connection_set_state(srv, con, CON_STATE_ERROR); - } + is_closed = 1; + break; default: break; } @@ -1125,6 +1119,12 @@ int connection_handle_read_state(server *srv, connection *con) { break; } + /* the connection got closed and we didn't got enough data to leave one of the READ states + * the only way is to leave here */ + if (is_closed && ostate == con->state) { + connection_set_state(srv, con, CON_STATE_ERROR); + } + chunkqueue_remove_finished_chunks(cq); return 0;