From 8440616f53056b2330393d1b0740c89a30376c67 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 13 Aug 2018 12:12:14 +0200 Subject: http: fix for tiny "HTTP/0.9" response Deal with tiny "HTTP/0.9" (header-less) responses by checking the status-line early, even before a full "HTTP/" is received to allow detecting 0.9 properly. Test 1266 and 1267 added to verify. Fixes #2420 Closes #2872 --- tests/server/sws.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'tests/server') diff --git a/tests/server/sws.c b/tests/server/sws.c index 4879cfa8b..fbe7761d8 100644 --- a/tests/server/sws.c +++ b/tests/server/sws.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2017, Daniel Stenberg, , et al. + * Copyright (C) 1998 - 2018, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -124,6 +124,8 @@ struct httprequest { bool connmon; /* monitor the state of the connection, log disconnects */ bool upgrade; /* test case allows upgrade to http2 */ bool upgrade_request; /* upgrade request found and allowed */ + bool close; /* similar to swsclose in response: close connection after + response is sent */ int done_processing; }; @@ -177,6 +179,9 @@ const char *serverlogfile = DEFAULT_LOGFILE; /* upgrade to http2 */ #define CMD_UPGRADE "upgrade" +/* close connection */ +#define CMD_SWSCLOSE "swsclose" + #define END_OF_HEADERS "\r\n\r\n" enum { @@ -361,7 +366,7 @@ static int parse_servercmd(struct httprequest *req) int error; filename = test2file(req->testno); - + req->close = FALSE; stream = fopen(filename, "rb"); if(!stream) { error = errno; @@ -414,6 +419,10 @@ static int parse_servercmd(struct httprequest *req) logmsg("enabled upgrade to http2"); req->upgrade = TRUE; } + else if(!strncmp(CMD_SWSCLOSE, cmd, strlen(CMD_SWSCLOSE))) { + logmsg("swsclose: close this connection after response"); + req->close = TRUE; + } else if(1 == sscanf(cmd, "pipe: %d", &num)) { logmsg("instructed to allow a pipe size of %d", num); if(num < 0) @@ -1194,7 +1203,7 @@ static int send_doc(curl_socket_t sock, struct httprequest *req) /* If the word 'swsclose' is present anywhere in the reply chunk, the connection will be closed after the data has been sent to the requesting client... */ - if(strstr(buffer, "swsclose") || !count) { + if(strstr(buffer, "swsclose") || !count || req->close) { persistent = FALSE; logmsg("connection close instruction \"swsclose\" found in response"); } -- cgit v1.2.3