Only process `Connection: close` header if full request was read (fixes #194) (#195)

master
Jessie Murray 3 years ago committed by GitHub
parent 1e4c6f8b96
commit 6556039e05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,7 +17,7 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: | run: |
apt-get -y update 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 - name: Build
run: make run: make
- name: Run Webdis and test - name: Run Webdis and test
@ -25,6 +25,7 @@ jobs:
./webdis .github/workflows/webdis-ci.json ./webdis .github/workflows/webdis-ci.json
sleep 2 sleep 2
./tests/basic.py ./tests/basic.py
./tests/curl-tests.sh
- name: Archive logs - name: Archive logs
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:

@ -182,6 +182,7 @@ http_client_on_message_complete(struct http_parser *p) {
/* keep-alive detection */ /* keep-alive detection */
if (c->parser.flags & F_CONNECTION_CLOSE) { if (c->parser.flags & F_CONNECTION_CLOSE) {
c->keep_alive = 0; 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 */ } else if(c->parser.http_major == 1 && c->parser.http_minor == 1) { /* 1.1 */
c->keep_alive = 1; c->keep_alive = 1;
} }

@ -40,6 +40,7 @@ struct http_client {
/* various flags. */ /* various flags. */
char keep_alive; char keep_alive;
char broken; char broken;
char fully_read;
char is_websocket; char is_websocket;
char http_version; char http_version;
char failed_alloc; char failed_alloc;

@ -63,7 +63,8 @@ worker_can_read(int fd, short event, void *p) {
if(c->failed_alloc) { if(c->failed_alloc) {
slog(c->w->s, WEBDIS_DEBUG, "503", 3); slog(c->w->s, WEBDIS_DEBUG, "503", 3);
http_send_error(c, 503, "Service Unavailable"); 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; c->broken = 1;
} else if(c->is_websocket) { } else if(c->is_websocket) {
/* we need to use the remaining (unparsed) data as the body. */ /* we need to use the remaining (unparsed) data as the body. */

@ -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
Loading…
Cancel
Save