-const char parsers_rcs[] = "$Id: parsers.c,v 1.156 2009/05/13 18:22:45 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.162 2009/05/25 15:40:52 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
*/
int skip_bytes;
skip_bytes = *cur++;
- skip_bytes = *cur++ << 8;
+ skip_bytes += *cur++ << 8;
assert(skip_bytes == *csp->iob->cur - 2 + ((*csp->iob->cur - 1) << 8));
*********************************************************************/
static jb_err server_connection(struct client_state *csp, char **header)
{
- /* Do we have a 'Connection: close' header? */
- if (strcmpic(*header, "Connection: close"))
+ if (!strcmpic(*header, "Connection: keep-alive"))
{
#ifdef FEATURE_CONNECTION_KEEP_ALIVE
- if ((csp->config->feature_flags &
- RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
- && !strcmpic(*header, "Connection: keep-alive"))
+ if ((csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE))
{
- /* Remember to keep the connection alive. */
csp->flags |= CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE;
}
- log_error(LOG_LEVEL_HEADER,
- "Keeping the server header '%s' around.", *header);
-#else
- char *old_header = *header;
- *header = strdup("Connection: close");
- if (header == NULL)
- {
- return JB_ERR_MEMORY;
+ if ((csp->flags & CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE))
+ {
+ log_error(LOG_LEVEL_HEADER,
+ "Keeping the server header '%s' around.", *header);
}
- log_error(LOG_LEVEL_HEADER, "Replaced: \'%s\' with \'%s\'", old_header, *header);
- freez(old_header);
+ else
#endif /* FEATURE_CONNECTION_KEEP_ALIVE */
+ {
+ char *old_header = *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);
+ }
}
/* Signal server_connection_adder() to return early. */
unsigned int keep_alive_timeout;
const char *timeout_position = strstr(*header, "timeout=");
- if ((NULL != timeout_position)
- && (1 != sscanf(timeout_position, "timeout=%u", &keep_alive_timeout)))
+ if ((NULL == timeout_position)
+ || (1 != sscanf(timeout_position, "timeout=%u", &keep_alive_timeout)))
{
log_error(LOG_LEVEL_ERROR, "Couldn't parse: %s", *header);
}
if (strcmpic(*header, wanted_header))
{
#ifdef FEATURE_CONNECTION_KEEP_ALIVE
- log_error(LOG_LEVEL_HEADER,
- "Keeping the client header '%s' around. "
- "The connection will not be kept alive.",
- *header);
-#else
- char *old_header = *header;
-
- *header = strdup(wanted_header);
- if (header == NULL)
- {
- return JB_ERR_MEMORY;
+ if (!(csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_SHARING))
+ {
+ log_error(LOG_LEVEL_HEADER,
+ "Keeping the client header '%s' around. "
+ "The connection will not be kept alive.",
+ *header);
}
- log_error(LOG_LEVEL_HEADER,
- "Replaced: \'%s\' with \'%s\'", old_header, *header);
- freez(old_header);
+ else
#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
+ {
+ 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);
+ }
}
#ifdef FEATURE_CONNECTION_KEEP_ALIVE
else
log_error(LOG_LEVEL_HEADER, "Randomizing: %s", *header);
now = time(NULL);
#ifdef HAVE_GMTIME_R
- timeptr = gmtime_r(&now, &gmt);
+ gmtime_r(&now, &gmt);
#elif FEATURE_PTHREAD
privoxy_mutex_lock(&gmtime_mutex);
- timeptr = gmtime(&now);
+ gmtime(&now);
privoxy_mutex_unlock(&gmtime_mutex);
#else
- timeptr = gmtime(&now);
+ gmtime(&now);
#endif
if (JB_ERR_OK != parse_header_time(header_time, &last_modified))
{
return JB_ERR_OK;
}
+ if ((csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
+ && (csp->http->ssl == 0))
+ {
+ csp->flags |= CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE;
+ }
+
log_error(LOG_LEVEL_HEADER, "Adding: %s", wanted_header);
return enlist(csp->headers, wanted_header);