-const char cgi_rcs[] = "$Id: cgi.c,v 1.90 2007/01/25 13:47:26 fabiankeil Exp $";
+const char cgi_rcs[] = "$Id: cgi.c,v 1.91 2007/01/27 13:09:16 fabiankeil Exp $";
/*********************************************************************
*
* File : $Source: /cvsroot/ijbswa/current/cgi.c,v $
*
* Revisions :
* $Log: cgi.c,v $
+ * Revision 1.91 2007/01/27 13:09:16 fabiankeil
+ * Add new config option "templdir" to
+ * change the templates directory.
+ *
* Revision 1.90 2007/01/25 13:47:26 fabiankeil
* Added "forwarding-failed" template support for error_response().
*
if (!err)
{
/* It worked */
- return finish_http_response(rsp);
+ return finish_http_response(csp, rsp);
}
else
{
return cgi_error_memory();
}
- return finish_http_response(rsp);
+ return finish_http_response(csp, rsp);
}
"\r\n";
cgi_error_memory_response->body =
"<html>\r\n"
- "<head><title>500 Internal Privoxy Error</title></head>\r\n"
+ "<head>\r\n"
+ " <title>500 Internal Privoxy Error</title>\r\n"
+ " <link rel=\"shortcut icon\" href=\"" CGI_PREFIX "error-favicon.ico\" type=\"image/x-icon\">"
+ "</head>\r\n"
"<body>\r\n"
"<h1>500 Internal Privoxy Error</h1>\r\n"
"<p>Privoxy <b>ran out of memory</b> while processing your request.</p>\r\n"
"500 Internal Privoxy Error";
static const char body_prefix[] =
"<html>\r\n"
- "<head><title>500 Internal Privoxy Error</title></head>\r\n"
+ "<head>\r\n"
+ " <title>500 Internal Privoxy Error</title>\r\n"
+ " <link rel=\"shortcut icon\" href=\"" CGI_PREFIX "error-favicon.ico\" type=\"image/x-icon\">"
+ "</head>\r\n"
"<body>\r\n"
"<h1>500 Internal Privoxy Error</h1>\r\n"
"<p>Privoxy encountered an error while processing your request:</p>\r\n"
"500 Internal Privoxy Error";
static const char body_prefix[] =
"<html>\r\n"
- "<head><title>500 Internal Privoxy Error</title></head>\r\n"
+ "<head>\r\n"
+ " <title>500 Internal Privoxy Error</title>\r\n"
+ " <link rel=\"shortcut icon\" href=\"" CGI_PREFIX "error-favicon.ico\" type=\"image/x-icon\">"
+ "</head>\r\n"
"<body>\r\n"
"<h1>500 Internal Privoxy Error</h1>\r\n"
"<p>Privoxy encountered an error while processing your request:</p>\r\n"
*
* Description : Fill in the missing headers in an http response,
* and flatten the headers to an http head.
+ * For HEAD requests the body is freed once
+ * the Content-Length header is set.
*
* Parameters :
* 1 : rsp = pointer to http_response to be processed
* On error, free()s rsp and returns cgi_error_memory()
*
*********************************************************************/
-struct http_response *finish_http_response(struct http_response *rsp)
+struct http_response *finish_http_response(const struct client_state *csp, struct http_response *rsp)
{
char buf[BUFFER_SIZE];
jb_err err;
err = enlist(rsp->headers, buf);
}
- if (strncmpic(rsp->status, "302", 3))
+ if (0 == strcmpic(csp->http->gpc, "head"))
+ {
+ /*
+ * The client only asked for the head. Dispose
+ * the body and log an offensive message.
+ *
+ * While it may seem to be a bit inefficient to
+ * prepare the body if it isn't needed, it's the
+ * only way to get the Content-Length right for
+ * dynamic pages. We could have disposed the body
+ * earlier, but not without duplicating the
+ * Content-Length setting code above.
+ */
+ log_error(LOG_LEVEL_CGI, "Preparing to give head to %s.", csp->ip_addr_str);
+ freez(rsp->body);
+ rsp->content_length = 0;
+ }
+
+ if ((rsp->status != NULL) && strncmpic(rsp->status, "302", 3))
{
/*
* If it's not a redirect without any content,