diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9af9a86..ac482a8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,7 +17,7 @@ jobs: - name: Install dependencies run: | apt-get -y update - apt-get -y --force-yes install make gcc libevent-dev libmsgpack-dev python3 + apt-get -y --force-yes install make gcc libevent-dev libmsgpack-dev python3 curl - name: Build run: make - name: Run Webdis and test @@ -25,6 +25,7 @@ jobs: ./webdis .github/workflows/webdis-ci.json sleep 2 ./tests/basic.py + ./tests/curl-tests.sh - name: Archive logs uses: actions/upload-artifact@v2 with: diff --git a/src/client.c b/src/client.c index be52616..3e8eda4 100644 --- a/src/client.c +++ b/src/client.c @@ -182,6 +182,7 @@ http_client_on_message_complete(struct http_parser *p) { /* keep-alive detection */ if (c->parser.flags & F_CONNECTION_CLOSE) { c->keep_alive = 0; + c->fully_read = 1; /* only *now* can we stop waiting for input */ } else if(c->parser.http_major == 1 && c->parser.http_minor == 1) { /* 1.1 */ c->keep_alive = 1; } diff --git a/src/client.h b/src/client.h index 72594ef..6b38992 100644 --- a/src/client.h +++ b/src/client.h @@ -40,6 +40,7 @@ struct http_client { /* various flags. */ char keep_alive; char broken; + char fully_read; char is_websocket; char http_version; char failed_alloc; diff --git a/src/worker.c b/src/worker.c index 2bf29d3..d5decef 100644 --- a/src/worker.c +++ b/src/worker.c @@ -63,7 +63,8 @@ worker_can_read(int fd, short event, void *p) { if(c->failed_alloc) { slog(c->w->s, WEBDIS_DEBUG, "503", 3); http_send_error(c, 503, "Service Unavailable"); - } else if (c->parser.flags & F_CONNECTION_CLOSE) { + } else if (c->parser.flags & F_CONNECTION_CLOSE && c->fully_read) { + /* only close if requested *and* we've already read the request in full */ c->broken = 1; } else if(c->is_websocket) { /* we need to use the remaining (unparsed) data as the body. */ diff --git a/tests/curl-tests.sh b/tests/curl-tests.sh new file mode 100755 index 0000000..254c439 --- /dev/null +++ b/tests/curl-tests.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +# exit on first error +set -e + +# GitHub issue #194 (connection: close + HTTP 100) +printf 'A%.0s' $(seq 1 10000) | curl -v -H 'Connection: close' -XPUT 'http://127.0.0.1:7379/SET/toobig' -d @- +if [[ $(curl -v 'http://127.0.0.1:7379/STRLEN/toobig.txt') != '10000' ]]; then exit 1; fi