I don't think this change is going to work because mod_dir does more
than just check if a redirect is going to be needed.  It also handles
the sending of index files.  This means that with this change running
ap_sub_req_* could result in a index file being sent, which is not the
correct behavior.

The sending of the index file still needs to be implemented as a handler.
I would suggest that we either back this change out, or move the uri
checking into to fixups phase to allow subrequests to determine if the
request will generate a HTTP_MOVED_PERMANANTLY response.  A patch is
attached, only minimally tested since an update of my tree has resulted
in undefined references to pthread_sigmask.

-Ryan

>   Index: CHANGES
>   ===================================================================
>   RCS file: /home/cvs/httpd-2.0/CHANGES,v
>   retrieving revision 1.99
>   retrieving revision 1.100
>   diff -u -d -b -w -u -r1.99 -r1.100
>   --- CHANGES 2001/02/20 20:50:05     1.99
>   +++ CHANGES 2001/02/21 01:04:39     1.100
>   @@ -1,5 +1,11 @@
>    Changes with Apache 2.0.12-dev
>    
>   +  *) Make mod_dir use a fixup for sending a redirect to the browser.
>   +     Before this, we were using a handler, which doesn't make much
>   +     sense, because the handler wasn't generating any data, it would
>   +     either return a redirect error code, or DECLINED.  This fits the
>   +     current hooks better.  [Ryan Morgan <[EMAIL PROTECTED]>]
>   +
>      *) Make the threaded MPM use APR threads instead of pthreads.
>         [Ryan Bloom]
>    
>   
>   
>   
>   1.29      +3 -4      httpd-2.0/modules/mappers/mod_dir.c
>   
>   Index: mod_dir.c
>   ===================================================================
>   RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_dir.c,v
>   retrieving revision 1.28
>   retrieving revision 1.29
>   diff -u -d -b -w -u -r1.28 -r1.29
>   --- mod_dir.c       2001/02/16 04:26:40     1.28
>   +++ mod_dir.c       2001/02/21 01:04:39     1.29
>   @@ -124,8 +124,9 @@
>        int num_names;
>        int error_notfound = 0;
>    
>   -    if(strcmp(r->handler,DIR_MAGIC_TYPE))
>   +    if (r->finfo.filetype != APR_DIR) {
>       return DECLINED;
>   +    }
>    
>        d = (dir_config_rec *) ap_get_module_config(r->per_dir_config,
>                                               &dir_module);
>   @@ -223,9 +224,7 @@
>    
>    static void register_hooks(apr_pool_t *p)
>    {
>   -    static const char * const aszSucc[]={ "mod_autoindex.c", NULL };
>   -
>   -    ap_hook_handler(handle_dir,NULL,aszSucc,APR_HOOK_MIDDLE);
>   +    ap_hook_fixups(handle_dir,NULL,NULL,APR_HOOK_MIDDLE);
>    }
>    
>    module AP_MODULE_DECLARE_DATA dir_module = {
Index: mod_dir.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/mappers/mod_dir.c,v
retrieving revision 1.29
diff -u -r1.29 mod_dir.c
--- mod_dir.c   2001/02/21 01:04:39     1.29
+++ mod_dir.c   2001/02/21 07:18:10
@@ -124,27 +124,13 @@
     int num_names;
     int error_notfound = 0;
 
-    if (r->finfo.filetype != APR_DIR) {
-       return DECLINED;
+    if (strcmp(r->handler,DIR_MAGIC_TYPE)) {
+        return DECLINED;
     }
 
     d = (dir_config_rec *) ap_get_module_config(r->per_dir_config,
                                                &dir_module);
 
-    if (r->uri[0] == '\0' || r->uri[strlen(r->uri) - 1] != '/') {
-        char *ifile;
-        if (r->args != NULL)
-            ifile = apr_pstrcat(r->pool, ap_escape_uri(r->pool, r->uri),
-                            "/", "?", r->args, NULL);
-        else
-            ifile = apr_pstrcat(r->pool, ap_escape_uri(r->pool, r->uri),
-                            "/", NULL);
-
-        apr_table_setn(r->headers_out, "Location",
-                  ap_construct_url(r->pool, ifile, r));
-        return HTTP_MOVED_PERMANENTLY;
-    }
-
     /* KLUDGE --- make the sub_req lookups happen in the right directory.
      * Fixing this in the sub_req_lookup functions themselves is difficult,
      * and would probably break virtual includes...
@@ -222,9 +208,35 @@
     return DECLINED;
 }
 
+static int fixup_url(request_rec *r)
+{
+    if (r->finfo.filetype != APR_DIR) {
+        return DECLINED;
+    }
+
+    if (r->uri[0] == '\0' || r->uri[strlen(r->uri) - 1] != '/') {
+        char *ifile;
+        if (r->args != NULL) {
+            ifile = apr_pstrcat(r->pool, ap_escape_uri(r->pool, r->uri),
+                                "/", "?", r->args, NULL);
+        }
+        else {
+            ifile = apr_pstrcat(r->pool, ap_escape_uri(r->pool, r->uri),
+                                "/", NULL);
+        }
+        apr_table_setn(r->headers_out, "Location",
+                       ap_construct_url(r->pool, ifile, r));
+        return HTTP_MOVED_PERMANENTLY;
+    }
+
+    return DECLINED;
+}
+
 static void register_hooks(apr_pool_t *p)
 {
-    ap_hook_fixups(handle_dir,NULL,NULL,APR_HOOK_MIDDLE);
+    static const char * const aszSucc[]={ "mod_autoindex.c", NULL };
+    ap_hook_handler(handle_dir,NULL,aszSucc,APR_HOOK_MIDDLE);
+    ap_hook_fixups(fixup_url,NULL,NULL,APR_HOOK_MIDDLE);
 }
 
 module AP_MODULE_DECLARE_DATA dir_module = {

Reply via email to