-const char parsers_rcs[] = "$Id: parsers.c,v 1.174 2009/06/05 16:54:27 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.177 2009/06/10 12:50:15 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/parsers.c,v $
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);
+static void create_content_length_header(unsigned long long content_length,
+ char *header, size_t buffer_length);
/*
* List of functions to run on a list of headers.
}
}
+#ifdef FEATURE_CONNECTION_KEEP_ALIVE
+ if ((JB_ERR_OK == err)
+ && (csp->flags & CSP_FLAG_MODIFIED)
+ && (csp->flags & CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE)
+ && !(csp->flags & CSP_FLAG_SERVER_CONTENT_LENGTH_SET))
+ {
+ char header[50];
+
+ create_content_length_header(csp->content_length, header, sizeof(header));
+ err = enlist(csp->headers, header);
+ if (JB_ERR_OK == err)
+ {
+ log_error(LOG_LEVEL_HEADER,
+ "Content modified with no Content-Length header set. "
+ "Created: %s.", header);
+ }
+ }
+#endif /* def FEATURE_CONNECTION_KEEP_ALIVE */
+
return err;
}
*********************************************************************/
static jb_err server_adjust_content_length(struct client_state *csp, char **header)
{
- const size_t max_header_length = 80;
-
/* Regenerate header if the content was modified. */
if (csp->flags & CSP_FLAG_MODIFIED)
{
+ const size_t header_length = 50;
freez(*header);
- *header = (char *) zalloc(max_header_length);
+ *header = malloc(header_length);
if (*header == NULL)
{
return JB_ERR_MEMORY;
}
-
- snprintf(*header, max_header_length, "Content-Length: %d",
- (int)csp->content_length);
- log_error(LOG_LEVEL_HEADER, "Adjusted Content-Length to %d",
- (int)csp->content_length);
+ create_content_length_header(csp->content_length, *header, header_length);
+ log_error(LOG_LEVEL_HEADER,
+ "Adjusted Content-Length to %llu", csp->content_length);
}
return JB_ERR_OK;
else
{
csp->expected_content_length = content_length;
+ csp->flags |= CSP_FLAG_SERVER_CONTENT_LENGTH_SET;
csp->flags |= CSP_FLAG_CONTENT_LENGTH_SET;
}
return JB_ERR_OK;
}
+#ifdef FEATURE_CONNECTION_KEEP_ALIVE
if ((csp->config->feature_flags & RUNTIME_FEATURE_CONNECTION_KEEP_ALIVE)
&& (csp->http->ssl == 0))
{
csp->flags |= CSP_FLAG_CLIENT_CONNECTION_KEEP_ALIVE;
}
+#endif /* FEATURE_CONNECTION_KEEP_ALIVE */
log_error(LOG_LEVEL_HEADER, "Adding: %s", wanted_header);
}
return connection_close;
}
+
+
+/*********************************************************************
+ *
+ * Function : create_content_length_header
+ *
+ * Description : Creates a Content-Length header.
+ *
+ * Parameters :
+ * 1 : content_length = The content length to be used in the header.
+ * 2 : header = Allocated space to safe the header.
+ * 3 : buffer_length = The length of the allocated space.
+ *
+ * Returns : void
+ *
+ *********************************************************************/
+static void create_content_length_header(unsigned long long content_length,
+ char *header, size_t buffer_length)
+{
+ snprintf(header, buffer_length, "Content-Length: %llu", content_length);
+}
+
+
/*
Local Variables:
tab-width: 3