From 8314e43f15b2660a6146442fadb1c25293fed8d9 Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Mon, 10 Feb 2014 14:42:18 +0000 Subject: [PATCH] Properly deal with Keep-Alive headers with timeout= parameters If the timeout still can't be parsed, use the configured timeout instead of preventing the client from keeping the connection alive. Should fix #3615312/#870 reported by Bernard Guillot. --- parsers.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/parsers.c b/parsers.c index b5644ef0..29d52e4d 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.281 2013/12/24 13:34:22 fabiankeil Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.282 2013/12/24 13:34:45 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -1735,7 +1735,7 @@ static jb_err proxy_authentication(struct client_state *csp, char **header) static jb_err client_keep_alive(struct client_state *csp, char **header) { unsigned int keep_alive_timeout; - const char *timeout_position = strstr(*header, ": "); + char *timeout_position; if (!(csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)) { @@ -1745,29 +1745,39 @@ static jb_err client_keep_alive(struct client_state *csp, char **header) return JB_ERR_OK; } + /* Check for parameter-less format "Keep-Alive: 100" */ + timeout_position = strstr(*header, ": "); if ((NULL == timeout_position) || (1 != sscanf(timeout_position, ": %u", &keep_alive_timeout))) { - log_error(LOG_LEVEL_ERROR, "Couldn't parse: %s", *header); - } - else - { - if (keep_alive_timeout < csp->config->keep_alive_timeout) + /* Assume parameter format "Keep-Alive: timeout=100" */ + timeout_position = strstr(*header, "timeout="); + if ((NULL == timeout_position) + || (1 != sscanf(timeout_position, "timeout=%u", &keep_alive_timeout))) { log_error(LOG_LEVEL_HEADER, - "Reducing keep-alive timeout from %u to %u.", - csp->config->keep_alive_timeout, keep_alive_timeout); - csp->server_connection.keep_alive_timeout = keep_alive_timeout; - } - else - { - /* XXX: Is this log worthy? */ - log_error(LOG_LEVEL_HEADER, - "Client keep-alive timeout is %u. Sticking with %u.", - keep_alive_timeout, csp->config->keep_alive_timeout); + "Couldn't parse: '%s'. Using default timeout %u", + *header, csp->config->keep_alive_timeout); + + return JB_ERR_OK; } } + if (keep_alive_timeout < csp->config->keep_alive_timeout) + { + log_error(LOG_LEVEL_HEADER, + "Reducing keep-alive timeout from %u to %u.", + csp->config->keep_alive_timeout, keep_alive_timeout); + csp->server_connection.keep_alive_timeout = keep_alive_timeout; + } + else + { + /* XXX: Is this log worthy? */ + log_error(LOG_LEVEL_HEADER, + "Client keep-alive timeout is %u. Sticking with %u.", + keep_alive_timeout, csp->config->keep_alive_timeout); + } + return JB_ERR_OK; } -- 2.39.2