From: Fabian Keil Date: Sun, 16 Nov 2008 12:43:49 +0000 (+0000) Subject: Turn keep-alive support into a runtime feature X-Git-Tag: v_3_0_11~163 X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=commitdiff_plain;h=cd275efe90ca39d461537daf389e79a3cd79e507 Turn keep-alive support into a runtime feature that is disabled by setting keep-alive-timeout to a negative value. --- diff --git a/jcc.c b/jcc.c index c80e91a7..cde64b09 100644 --- a/jcc.c +++ b/jcc.c @@ -1,4 +1,4 @@ -const char jcc_rcs[] = "$Id: jcc.c,v 1.203 2008/11/06 18:34:35 fabiankeil Exp $"; +const char jcc_rcs[] = "$Id: jcc.c,v 1.204 2008/11/06 19:42:17 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/jcc.c,v $ @@ -33,6 +33,10 @@ const char jcc_rcs[] = "$Id: jcc.c,v 1.203 2008/11/06 18:34:35 fabiankeil Exp $" * * Revisions : * $Log: jcc.c,v $ + * Revision 1.204 2008/11/06 19:42:17 fabiankeil + * Fix last-chunk detection hack to also apply + * if buf[] contains nothing but the last-chunk. + * * Revision 1.203 2008/11/06 18:34:35 fabiankeil * Factor receive_client_request() and * parse_client_request() out of chat(). @@ -3158,7 +3162,8 @@ static void serve(struct client_state *csp) if (csp->sfd != JB_INVALID_SOCKET) { #ifdef FEATURE_CONNECTION_KEEP_ALIVE - if ((csp->flags & CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE)) + if ((csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE) + && (csp->flags & CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE)) { remember_connection(csp->sfd, csp->http, forward_url(csp, csp->http)); } diff --git a/loadcfg.c b/loadcfg.c index a2e2cf49..1560697a 100644 --- a/loadcfg.c +++ b/loadcfg.c @@ -1,4 +1,4 @@ -const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.80 2008/08/31 15:59:03 fabiankeil Exp $"; +const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.81 2008/11/13 09:08:42 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/loadcfg.c,v $ @@ -35,6 +35,9 @@ const char loadcfg_rcs[] = "$Id: loadcfg.c,v 1.80 2008/08/31 15:59:03 fabiankeil * * Revisions : * $Log: loadcfg.c,v $ + * Revision 1.81 2008/11/13 09:08:42 fabiankeil + * Add new config option: keep-alive-timeout. + * * Revision 1.80 2008/08/31 15:59:03 fabiankeil * There's no reason to let remote toggling support depend * on FEATURE_CGI_EDIT_ACTIONS, so make sure it doesn't. @@ -1346,12 +1349,12 @@ struct configuration_spec * load_config(void) int timeout = atoi(arg); if (0 <= timeout) { + config->feature_flags |= RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE; keep_alive_timeout = timeout; } else { - log_error(LOG_LEVEL_FATAL, - "Invalid keep-alive-timeout value: %s.", arg); + config->feature_flags &= ~RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE; } } continue; diff --git a/parsers.c b/parsers.c index 329ad68b..88530a85 100644 --- a/parsers.c +++ b/parsers.c @@ -1,4 +1,4 @@ -const char parsers_rcs[] = "$Id: parsers.c,v 1.146 2008/10/12 16:46:35 fabiankeil Exp $"; +const char parsers_rcs[] = "$Id: parsers.c,v 1.147 2008/11/04 17:20:31 fabiankeil Exp $"; /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/parsers.c,v $ @@ -44,6 +44,10 @@ const char parsers_rcs[] = "$Id: parsers.c,v 1.146 2008/10/12 16:46:35 fabiankei * * Revisions : * $Log: parsers.c,v $ + * Revision 1.147 2008/11/04 17:20:31 fabiankeil + * HTTP/1.1 responses without Connection + * header imply keep-alive. Act accordingly. + * * Revision 1.146 2008/10/12 16:46:35 fabiankeil * Remove obsolete warning about delayed delivery with chunked * transfer encoding and FEATURE_CONNECTION_KEEP_ALIVE enabled. @@ -965,6 +969,7 @@ static jb_err create_forged_referrer(char **header, const char *hostport); static jb_err create_fake_referrer(char **header, const char *fake_referrer); static jb_err handle_conditional_hide_referrer_parameter(char **header, const char *host, const int parameter_conditional_block); +static const char *get_appropiate_connection_header(const struct client_state *csp); /* * List of functions to run on a list of headers. @@ -2361,7 +2366,9 @@ static jb_err server_connection(struct client_state *csp, char **header) if (strcmpic(*header, "Connection: close")) { #ifdef FEATURE_CONNECTION_KEEP_ALIVE - if (!strcmpic(*header, "Connection: keep-alive")) + if ((csp->config->feature_flags & + RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE) + && !strcmpic(*header, "Connection: keep-alive")) { /* Remember to keep the connection alive. */ csp->flags |= CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE; @@ -2405,11 +2412,7 @@ static jb_err server_connection(struct client_state *csp, char **header) static jb_err client_connection(struct client_state *csp, char **header) { char *old_header = *header; -#ifdef FEATURE_CONNECTION_KEEP_ALIVE - static const char wanted_header[] = "Connection: keep-alive"; -#else - static const char wanted_header[] = "Connection: close"; -#endif /* FEATURE_CONNECTION_KEEP_ALIVE */ + const char *wanted_header = get_appropiate_connection_header(csp); if (strcmpic(*header, wanted_header)) { @@ -4083,7 +4086,9 @@ static jb_err server_connection_close_adder(struct client_state *csp) /* * XXX: if we downgraded the response, this check will fail. */ - if ((NULL != response_status_line) + if ((csp->config->feature_flags & + RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE) + && (NULL != response_status_line) && !strncmpic(response_status_line, "HTTP/1.1", 8)) { log_error(LOG_LEVEL_HEADER, "A HTTP/1.1 response " @@ -4113,12 +4118,8 @@ static jb_err server_connection_close_adder(struct client_state *csp) *********************************************************************/ static jb_err client_connection_header_adder(struct client_state *csp) { -#ifdef FEATURE_CONNECTION_KEEP_ALIVE - static const char wanted_header[] = "Connection: keep-alive"; -#else - static const char wanted_header[] = "Connection: close"; -#endif /* FEATURE_CONNECTION_KEEP_ALIVE */ const unsigned int flags = csp->flags; + const char *wanted_header = get_appropiate_connection_header(csp); if (!(flags & CSP_FLAG_CLIENT_HEADER_PARSING_DONE) && (flags & CSP_FLAG_CLIENT_CONNECTION_HEADER_SET)) @@ -4670,6 +4671,32 @@ static jb_err handle_conditional_hide_referrer_parameter(char **header, } + +/********************************************************************* + * + * Function : get_appropiate_connection_header + * + * Description : Returns an appropiate Connection header + * depending on whether or not we try to keep + * the connection to the server alive. + * + * Parameters : + * 1 : csp = Current client state (buffers, headers, etc...) + * + * Returns : Pointer to statically allocated header buffer. + * + *********************************************************************/ +static const char *get_appropiate_connection_header(const struct client_state *csp) +{ + static const char connection_keep_alive[] = "Connection: keep-alive"; + static const char connection_close[] = "Connection: close"; + + if ((csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)) + { + return connection_keep_alive; + } + return connection_close; +} /* Local Variables: tab-width: 3 diff --git a/project.h b/project.h index 3411250d..088b8644 100644 --- a/project.h +++ b/project.h @@ -1,7 +1,7 @@ #ifndef PROJECT_H_INCLUDED #define PROJECT_H_INCLUDED /** Version string. */ -#define PROJECT_H_VERSION "$Id: project.h,v 1.122 2008/10/16 07:11:34 fabiankeil Exp $" +#define PROJECT_H_VERSION "$Id: project.h,v 1.123 2008/11/10 16:55:59 fabiankeil Exp $" /********************************************************************* * * File : $Source: /cvsroot/ijbswa/current/project.h,v $ @@ -37,6 +37,9 @@ * * Revisions : * $Log: project.h,v $ + * Revision 1.123 2008/11/10 16:55:59 fabiankeil + * Fix a gcc44 warning (in filters.c). + * * Revision 1.122 2008/10/16 07:11:34 fabiankeil * Fix a bunch of gcc44 conversion warnings. * @@ -1682,6 +1685,8 @@ struct access_control_list /** configuration_spec::feature_flags: Allow to block or redirect CGI requests. */ #define RUNTIME_FEATURE_CGI_CRUNCHING 64U +/** configuration_spec::feature_flags: Try to keep the connection to the server alive. */ +#define RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE 128U /** * Data loaded from the configuration file.