On 05/26/2007 08:50 PM, [EMAIL PROTECTED] wrote:
> Author: niq
> Date: Sat May 26 11:50:18 2007
> New Revision: 541926
>
> URL: http://svn.apache.org/viewvc?view=rev&rev=541926
> Log:
> PR#39710 - badly broken errordocuments for CGI
>
> We've just had another duplicate report of this on bugzilla.
> We've got a simple patch, and people asking WTF is going on
> with inaction. Noone seems clear on why the patch shouldn't
> be applied (http://marc.info/?l=apache-httpd-dev&m=117760311129386&w=2).
>
> Modified:
> httpd/httpd/trunk/modules/generators/mod_cgi.c
This breaks mod_cache with the following simple CGI script and mod_cache:
#!/usr/bin/perl
print "Last-Modified: Thu, 16 Nov 2006 20:32:40 GMT\n";
print "Cache-Control: max-age=0\n";
print "Content-type: text/plain; charset=iso-8859-1\n\n";
print "Hello World\n";
It breaks once the request is cached and mod_cache tries to revalidate the stale
cached entity. I guess this was one of the reasons for r231167 (
http://svn.apache.org/viewvc?view=rev&revision=231167). In order to get this
sorted
out I propose to add the following patch on top of yours:
Index: modules/generators/mod_cgi.c
===================================================================
--- modules/generators/mod_cgi.c»·······(Revision 541971)
+++ modules/generators/mod_cgi.c»·······(Arbeitskopie)
@@ -929,7 +929,34 @@
int ret;
·
if ((ret = ap_scan_script_header_err_brigade(r, bb, sbuf))) {
- return log_script(r, conf, ret, dbuf, sbuf, bb, script_err);
+ ret = log_script(r, conf, ret, dbuf, sbuf, bb, script_err);
+
+ /*
+ * ret could be HTTP_NOT_MODIFIED in the case that the CGI script
+ * does not set an explicit status and ap_meets_conditions, which
+ * is called by ap_scan_script_header_err_brigade, detects that
+ * the conditions of the requests are met and the response is
+ * not modified.
+ * In this case set r->status and return OK in order to prevent
+ * running through the error processing stack as this would
+ * break with mod_cache, if the conditions had been set by
+ * mod_cache itself to validate a stale entity.
+ * BTW: We circumvent the error processing stack anyway if the
+ * CGI script set an explicit status code (whatever it is) and
+ * the only possible values for ret here are:
+ *
+ * HTTP_NOT_MODIFIED (set by ap_meets_conditions)
+ * HTTP_PRECONDITION_FAILED (set by ap_meets_conditions)
+ * HTTP_INTERNAL_SERVER_ERROR (if something went wrong during the
+ * processing of the response of the CGI script, e.g broken headers
+ * or a crashed CGI process).
+ */
+ if (ret == HTTP_NOT_MODIFIED) {
+ r->status = ret;
+ return OK;
+ }
+
+ return ret;
}
·
location = apr_table_get(r->headers_out, "Location");
After applying this patch the
#!/bin/sh
echo "Foo"
script still fails with a correctly generated error page.
If the patch above is regarded correct it needs to be applied to mod_cgid.c as
well
as this currently also breaks with mod_cache (same code as in your patch).
Regards
Rüdiger
Index: modules/generators/mod_cgi.c
===================================================================
--- modules/generators/mod_cgi.c (Revision 541971)
+++ modules/generators/mod_cgi.c (Arbeitskopie)
@@ -929,7 +929,34 @@
int ret;
if ((ret = ap_scan_script_header_err_brigade(r, bb, sbuf))) {
- return log_script(r, conf, ret, dbuf, sbuf, bb, script_err);
+ ret = log_script(r, conf, ret, dbuf, sbuf, bb, script_err);
+
+ /*
+ * ret could be HTTP_NOT_MODIFIED in the case that the CGI script
+ * does not set an explicit status and ap_meets_conditions, which
+ * is called by ap_scan_script_header_err_brigade, detects that
+ * the conditions of the requests are met and the response is
+ * not modified.
+ * In this case set r->status and return OK in order to prevent
+ * running through the error processing stack as this would
+ * break with mod_cache, if the conditions had been set by
+ * mod_cache itself to validate a stale entity.
+ * BTW: We circumvent the error processing stack anyway if the
+ * CGI script set an explicit status code (whatever it is) and
+ * the only possible values for ret here are:
+ *
+ * HTTP_NOT_MODIFIED (set by ap_meets_conditions)
+ * HTTP_PRECONDITION_FAILED (set by ap_meets_conditions)
+ * HTTP_INTERNAL_SERVER_ERROR (if something went wrong during the
+ * processing of the response of the CGI script, e.g broken headers
+ * or a crashed CGI process).
+ */
+ if (ret == HTTP_NOT_MODIFIED) {
+ r->status = ret;
+ return OK;
+ }
+
+ return ret;
}
location = apr_table_get(r->headers_out, "Location");