-const char parsers_rcs[] = "$Id: parsers.c,v 1.178 2009/06/11 14:13:19 david__schmidt Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.187 2009/06/30 18:32:04 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
*********************************************************************/
static jb_err server_connection(struct client_state *csp, char **header)
{
- if (!strcmpic(*header, "Connection: keep-alive"))
+ if (!strcmpic(*header, "Connection: keep-alive")
+#ifdef FEATURE_CONNECTION_KEEP_ALIVE
+ && !(csp->flags & CSP_FLAG_SERVER_SOCKET_TAINTED)
+#endif
+ )
{
#ifdef FEATURE_CONNECTION_KEEP_ALIVE
if ((csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE))
*
* Function : server_keep_alive
*
- * Description : Stores the servers keep alive timeout.
+ * Description : Stores the server's keep alive timeout.
*
* Parameters :
* 1 : csp = Current client state (buffers, headers, etc...)
#else
timeptr = gmtime(&last_modified);
#endif
- strftime(newheader, sizeof(newheader), "%a, %d %b %Y %H:%M:%S GMT", timeptr);
+ if ((NULL == timeptr) || !strftime(newheader,
+ sizeof(newheader), "%a, %d %b %Y %H:%M:%S GMT", timeptr))
+ {
+ log_error(LOG_LEVEL_ERROR,
+ "Randomizing '%s' failed. Crunching the header without replacement.",
+ *header);
+ freez(*header);
+ return JB_ERR_OK;
+ }
+
freez(*header);
*header = strdup("Last-Modified: ");
string_append(header, newheader);
#else
timeptr = gmtime(&tm);
#endif
- if (!strftime(newheader, sizeof(newheader),
- "%a, %d %b %Y %H:%M:%S GMT", timeptr))
+ if ((NULL == timeptr) || !strftime(newheader,
+ sizeof(newheader), "%a, %d %b %Y %H:%M:%S GMT", timeptr))
{
log_error(LOG_LEVEL_ERROR,
- "Randomizing %s failed. Keeping the header unmodified.");
+ "Randomizing '%s' failed. Crunching the header without replacement.",
+ *header);
+ freez(*header);
return JB_ERR_OK;
}
if ((csp->config->feature_flags &
RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
&& (NULL != response_status_line)
- && !strncmpic(response_status_line, "HTTP/1.1", 8))
+ && !strncmpic(response_status_line, "HTTP/1.1", 8)
+#ifdef FEATURE_CONNECTION_KEEP_ALIVE
+ && !(csp->flags & CSP_FLAG_SERVER_SOCKET_TAINTED)
+#endif
+ && (csp->http->status == 200)
+ )
{
+ /*
+ * XXX: not doing this for status codes other than 200 works
+ * around problems with broken servers that will keep the
+ * connection open, but terminate the connection when the
+ * next request arrives. Once we are able to figure out which
+ * requests are safe to send again, this will probably no
+ * longer be necessary.
+ */
log_error(LOG_LEVEL_HEADER, "A HTTP/1.1 response "
"without Connection header implies keep-alive.");
csp->flags |= CSP_FLAG_SERVER_CONNECTION_KEEP_ALIVE;
static const char proxy_connection_header[] = "Proxy-Connection: keep-alive";
jb_err err = JB_ERR_OK;
- if ((csp->flags & CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE))
+ if ((csp->flags & CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE)
+ && !(csp->flags & CSP_FLAG_SERVER_SOCKET_TAINTED))
{
log_error(LOG_LEVEL_HEADER, "Adding: %s", proxy_connection_header);
err = enlist(csp->headers, proxy_connection_header);
#ifdef FEATURE_CONNECTION_KEEP_ALIVE
if ((csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
- && (csp->http->ssl == 0))
+ && (csp->http->ssl == 0)
+ && !strcmpic(csp->http->ver, "HTTP/1.1"))
{
csp->flags |= CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE;
}
static const char connection_close[] = "Connection: close";
if ((csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
+#ifdef FEATURE_CONNECTION_KEEP_ALIVE
+ && !(csp->flags & CSP_FLAG_SERVER_SOCKET_TAINTED)
+#endif
&& (csp->http->ssl == 0))
{
return connection_keep_alive;