From: Fabian Keil Date: Sat, 8 Feb 2025 12:55:15 +0000 (+0100) Subject: Look for the "keep-alive" keyword more carefully X-Git-Url: http://www.privoxy.org/gitweb/@default-cgi@/faq/%22https:/%22javascript:back()/user-manual/documentation.html?a=commitdiff_plain;h=d34d4df1ee741844a53c2bfaf36b5f60fd165e62;p=privoxy.git Look for the "keep-alive" keyword more carefully ... in Connection headers. Previously connections were not kept alive if the Connection header contained additional keywords like "Upgrade". --- diff --git a/parsers.c b/parsers.c index a14f970d..5428a445 100644 --- a/parsers.c +++ b/parsers.c @@ -1791,6 +1791,51 @@ static jb_err filter_header(struct client_state *csp, char **header) } +/********************************************************************* + * + * Function : connection_header_contains_keep_alive_keyword + * + * Description : Checks wether or not a Connection header contains + * the keep-alive keyword. + * + * Parameters : + * 1 : header = The Connection header to check. + * + * Returns : TRUE or FALSE. + * + *********************************************************************/ +static int connection_header_contains_keep_alive_keyword(const char *header) +{ + char *header_content; + char *keywords[4]; + int segments; + int keep_alive_keyword_present = FALSE; + + header_content = strdup(header+11); + if (header_content == NULL) + { + log_error(LOG_LEVEL_ERROR, + "Out of memory while looking for keep-alive keyword in %s", header); + return FALSE; + } + + segments = ssplit(header_content, " ,", keywords, SZ(keywords)); + while (segments-- > 0) + { + if (!strcmpic(keywords[segments], "keep-alive")) + { + keep_alive_keyword_present = TRUE; + break; + } + } + + freez(header_content); + + return keep_alive_keyword_present; + +} + + /********************************************************************* * * Function : server_connection @@ -1811,7 +1856,7 @@ static jb_err filter_header(struct client_state *csp, char **header) *********************************************************************/ static jb_err server_connection(struct client_state *csp, char **header) { - if (!strcmpic(*header, "Connection: keep-alive") + if (connection_header_contains_keep_alive_keyword(*header) #ifdef FEATURE_CONNECTION_KEEP_ALIVE && !(csp->flags & CSP_FLAG_SERVER_SOCKET_TAINTED) #endif