Hi.

I wrote a small CGI script to make any CGI-enabled server into WebDAV
resource, but I noticed mod_cgi is blocking certain HTTP/WebDAV request
to make it run properly. I had to patch mod_cgi.c.

Is there any reason to prohibit CGI script from handling methods
other than GET and HEAD? In mod_cgi.c (both 1.3 and 2.0), it says:

  if (r->method_number == M_OPTIONS) {
    /* 99 out of 100 CGI scripts, this is all they support */
    r->allowed |= (AP_METHOD_BIT << M_GET);
    r->allowed |= (AP_METHOD_BIT << M_POST);
    return DECLINED;
  }

but I can't think of any reason to prohibit it just because 99
out of 100 CGI scripts don't support it.

My patch (this is for 1.3) adds new directive "PassThruRequest (on|off)"
to allow CGI script handle any HTTP request method.

--
Taisuke Yamada <[EMAIL PROTECTED]>
Internet Initiative Japan Inc., Technical Planning Division

--- cut here --- cut here --- cut here --- cut here --- cut here ---
--- mod_cgi.c.orig      Mon Mar  4 13:35:06 2002
+++ mod_cgi.c   Mon Mar  4 13:33:16 2002
@@ -102,6 +102,7 @@
     char *logname;
     long logbytes;
     int bufbytes;
+    int passthru;
 } cgi_server_conf;
 
 static void *create_cgi_config(pool *p, server_rec *s)
@@ -112,6 +113,7 @@
     c->logname = NULL;
     c->logbytes = DEFAULT_LOGBYTES;
     c->bufbytes = DEFAULT_BUFBYTES;
+    c->passthru = 1;
 
     return c;
 }
@@ -153,6 +155,16 @@
     return NULL;
 }
 
+static const char *set_passthru(cmd_parms *cmd, void *dummy, int flag)
+{
+    server_rec *s = cmd->server;
+    cgi_server_conf *conf =
+    (cgi_server_conf *) ap_get_module_config(s->module_config, &cgi_module);
+
+    conf->passthru = flag;
+    return NULL;
+}
+
 static const command_rec cgi_cmds[] =
 {
     {"ScriptLog", set_scriptlog, NULL, RSRC_CONF, TAKE1,
@@ -161,6 +173,8 @@
      "the maximum length (in bytes) of the script debug log"},
     {"ScriptLogBuffer", set_scriptlog_buffer, NULL, RSRC_CONF, TAKE1,
      "the maximum size (in bytes) to record of a POST request"},
+    {"PassThruRequest", set_passthru, NULL, OR_ALL, FLAG,
+     "whether or not to let CGI handle all requests, including OPTIONS"},
     {NULL}
 };
 
@@ -380,7 +394,7 @@
 
     struct cgi_child_stuff cld;
 
-    if (r->method_number == M_OPTIONS) {
+    if (! conf->passthru && r->method_number == M_OPTIONS) {
        /* 99 out of 100 CGI scripts, this is all they support */
        r->allowed |= (1 << M_GET);
        r->allowed |= (1 << M_POST);

Reply via email to