From 8601b03ead442873532c4aaf3436ef768b6380df Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Sun, 6 Nov 2011 10:04:55 +0100 Subject: [PATCH] Do not set Connection: keep-alive unless -enable_keep_alive is set --- mongoose.c | 5 +++-- test/test.pl | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/mongoose.c b/mongoose.c index 117859eb..bae28948 100644 --- a/mongoose.c +++ b/mongoose.c @@ -781,8 +781,9 @@ static int match_extension(const char *path, const char *ext_list) { static int should_keep_alive(const struct mg_connection *conn) { const char *http_version = conn->request_info.http_version; const char *header = mg_get_header(conn, "Connection"); - return (header == NULL && http_version && !strcmp(http_version, "1.1")) || - (header != NULL && !mg_strcasecmp(header, "keep-alive")); + return (!mg_strcasecmp(conn->ctx->config[ENABLE_KEEP_ALIVE], "yes") && + (header == NULL && http_version && !strcmp(http_version, "1.1"))) || + (header != NULL && !mg_strcasecmp(header, "keep-alive")); } static const char *suggest_connection_header(const struct mg_connection *conn) { diff --git a/test/test.pl b/test/test.pl index 36aad115..33c54dd2 100644 --- a/test/test.pl +++ b/test/test.pl @@ -229,6 +229,7 @@ o("GET /$test_dir_uri/x/ HTTP/1.0\n\n", "SCRIPT_FILENAME=test/test_dir/x/index.cgi", 'SCRIPT_FILENAME'); o("GET /ta/x/ HTTP/1.0\n\n", "SCRIPT_NAME=/ta/x/index.cgi", 'Aliases SCRIPT_NAME'); +o("GET /hello.txt HTTP/1.1\n\n", 'Connection: close', 'No keep-alive'); #o("GET /hello.txt HTTP/1.1\n\n GET /hello.txt HTTP/1.0\n\n", # 'HTTP/1.1 200.+keep-alive.+HTTP/1.1 200.+close', # 'Request pipelining', 2);