From 63a8b3ec23c0bad6b6d7f6251abaa7ea6d030e1f Mon Sep 17 00:00:00 2001 From: Fabian Keil Date: Sat, 11 Jul 2009 11:17:35 +0000 Subject: [PATCH] For HTTP/1.1 requests other than CONNECT requests, assume persistence unless the client says otherwise. --- jcc.c | 11 ++++++++++- parsers.c | 54 ++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 17 deletions(-) diff --git a/jcc.c b/jcc.c index 7cb6cbff..ed17ba82 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.263 2009/07/05 13:24:04 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.264 2009/07/07 16:42:26 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -1415,6 +1415,15 @@ static jb_err parse_client_request(struct client_state *csp) struct http_request *http = csp->http; jb_err err; +#ifdef FEATURE_CONNECTION_KEEP_ALIVE + if ((!strcmpic(csp->http->ver, "HTTP/1.1")) + && (csp->http->ssl == 0)) + { + /* Assume persistence until further notice */ + csp->flags |= CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE; + } +#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ + err = sed(csp, FILTER_CLIENT_HEADERS); if (JB_ERR_OK != err) { diff --git a/parsers.c b/parsers.c index 98909c37..1fc52c75 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.193 2009/07/11 11:15:53 fabiankeil Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.194 2009/07/11 11:16:19 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -1741,32 +1741,54 @@ static jb_err client_keep_alive(struct client_state *csp, char **header) *********************************************************************/ static jb_err client_connection(struct client_state *csp, char **header) { - const char *wanted_header = get_appropiate_connection_header(csp); + static const char connection_close[] = "Connection: close"; - if (strcmpic(*header, wanted_header)) + if (!strcmpic(*header, connection_close)) { #ifdef FEATURE_CONNECTION_KEEP_ALIVE - if (!(csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING)) + if ((csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING)) + { + if (!strcmpic(csp->http->ver, "HTTP/1.1")) + { + log_error(LOG_LEVEL_HEADER, + "Removing \'%s\' to imply keep-alive.", *header); + freez(*header); + } + else + { + char *old_header = *header; + + *header = strdup("Connection: keep-alive"); + if (header == NULL) + { + return JB_ERR_MEMORY; + } + log_error(LOG_LEVEL_HEADER, + "Replaced: \'%s\' with \'%s\'", old_header, *header); + freez(old_header); + } + csp->flags |= CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE; + } + else { log_error(LOG_LEVEL_HEADER, "Keeping the client header '%s' around. " "The connection will not be kept alive.", *header); + csp->flags &= ~CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE; } - else -#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ - { - char *old_header = *header; +#else + char *old_header = *header; - *header = strdup(wanted_header); - if (header == NULL) - { - return JB_ERR_MEMORY; - } - log_error(LOG_LEVEL_HEADER, - "Replaced: \'%s\' with \'%s\'", old_header, *header); - freez(old_header); + *header = strdup(connection_close); + if (header == NULL) + { + return JB_ERR_MEMORY; } + log_error(LOG_LEVEL_HEADER, + "Replaced: \'%s\' with \'%s\'", old_header, *header); + freez(old_header); +#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */ } #ifdef FEATURE_CONNECTION_KEEP_ALIVE else -- 2.39.2