You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ni...@apache.org on 2009/06/16 23:57:25 UTC

svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Author: niq
Date: Tue Jun 16 21:57:25 2009
New Revision: 785425

URL: http://svn.apache.org/viewvc?rev=785425&view=rev
Log:
Add DefaultHandler directive to mod_dir.
PR 47184

Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/modules/mappers/mod_dir.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=785425&r1=785424&r2=785425&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Tue Jun 16 21:57:25 2009
@@ -6,6 +6,10 @@
      mod_proxy_ajp: Avoid delivering content from a previous request which
      failed to send a request body. PR 46949 [Ruediger Pluem]
 
+  *) mod_dir: add DefaultHandler directive, to enable admin to specify
+     an action to happen when a URL maps to no file, without resorting
+     to ErrorDocument or mod_rewrite.  PR 47184 [Nick Kew]
+
   *) mod_cgid: Do not leak the listening Unix socket file descriptor to the
      CGI process. PR 47335 [Kornél Pál <kornelpal gmail.com>]
 

Modified: httpd/httpd/trunk/modules/mappers/mod_dir.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mappers/mod_dir.c?rev=785425&r1=785424&r2=785425&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/mappers/mod_dir.c (original)
+++ httpd/httpd/trunk/modules/mappers/mod_dir.c Tue Jun 16 21:57:25 2009
@@ -40,6 +40,7 @@
 typedef struct dir_config_struct {
     apr_array_header_t *index_names;
     slash_cfg do_slash;
+    const char *dflt;
 } dir_config_rec;
 
 #define DIR_CMD_PERMS OR_INDEXES
@@ -82,6 +83,9 @@
 
 static const command_rec dir_cmds[] =
 {
+    AP_INIT_TAKE1("DefaultHandler", ap_set_string_slot,
+                  (void*)APR_OFFSETOF(dir_config_rec, dflt),
+                  DIR_CMD_PERMS, "Set a default handler"),
     AP_INIT_RAW_ARGS("DirectoryIndex", add_index, NULL, DIR_CMD_PERMS,
                     "a list of file names"),
     AP_INIT_FLAG("DirectorySlash", configure_slash, NULL, DIR_CMD_PERMS,
@@ -107,9 +111,53 @@
     new->index_names = add->index_names ? add->index_names : base->index_names;
     new->do_slash =
         (add->do_slash == SLASH_UNSET) ? base->do_slash : add->do_slash;
+    new->dflt = add->dflt ? add->dflt : base->dflt;
     return new;
 }
 
+static int fixup_dflt(request_rec *r)
+{
+    dir_config_rec *d = ap_get_module_config(r->per_dir_config, &dir_module);
+    const char *name_ptr;
+    request_rec *rr;
+    int error_notfound = 0;
+    if ((r->finfo.filetype != APR_NOFILE) || (r->handler != NULL)) {
+        return DECLINED;
+    }
+    name_ptr = d->dflt;
+    if (r->args != NULL) {
+        name_ptr = apr_pstrcat(r->pool, name_ptr, "?", r->args, NULL);
+    }
+    rr = ap_sub_req_lookup_uri(name_ptr, r, r->output_filters);
+    if (rr->status == HTTP_OK
+        && (   (rr->handler && !strcmp(rr->handler, "proxy-server"))
+            || rr->finfo.filetype == APR_REG)) {
+        ap_internal_fast_redirect(rr, r);
+        return OK;
+    }
+    else if (ap_is_HTTP_REDIRECT(rr->status)) {
+
+        apr_pool_join(r->pool, rr->pool);
+        r->notes = apr_table_overlay(r->pool, r->notes, rr->notes);
+        r->headers_out = apr_table_overlay(r->pool, r->headers_out,
+                                           rr->headers_out);
+        r->err_headers_out = apr_table_overlay(r->pool, r->err_headers_out,
+                                               rr->err_headers_out);
+        error_notfound = rr->status;
+    }
+    else if (rr->status && rr->status != HTTP_NOT_FOUND
+             && rr->status != HTTP_OK) {
+        error_notfound = rr->status;
+    }
+
+    ap_destroy_sub_req(rr);
+    if (error_notfound) {
+        return error_notfound;
+    }
+
+    /* nothing for us to do, pass on through */
+    return DECLINED;
+}
 static int fixup_dir(request_rec *r)
 {
     dir_config_rec *d;
@@ -256,6 +304,7 @@
 static void register_hooks(apr_pool_t *p)
 {
     ap_hook_fixups(fixup_dir,NULL,NULL,APR_HOOK_LAST);
+    ap_hook_fixups(fixup_dflt,NULL,NULL,APR_HOOK_LAST);
 }
 
 module AP_MODULE_DECLARE_DATA dir_module = {



Re: svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Posted by Graham Dumpleton <gr...@gmail.com>.
2009/6/18 Rich Bowen <rb...@rcbowen.com>:
>
> On Jun 16, 2009, at 18:43, William A. Rowe, Jr. wrote:
>
>> William A. Rowe, Jr. wrote:
>>>
>>> This might be NotFoundHandler or for dir-not-file, ListingHandler.
>>
>> Sorry; not ListingHandler, but IndexHandler.
>>
>> But there is no point to a NotFoundHandler; the existing mechanics
>> in ScriptAlias combined with PATH_INFO solve that problem already.
>>
>> I think the interest was in handling the directory resource URI and
>> that would be an IndexHandler, absolutely.
>
> The intent was to call a something (I'd call it a handler) for requests that
> don't correspond to a resource. This is to answer the frequent
> configuration:
>
> RewriteEngine On
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteRule . index.php [PT]
>
> ie - if the request wasn't for a file, send the request directly to
> index.php (or index.pl, or wordpress.php, or whatever)
>
> and variations thereof that occur in every PHP web app I install these days.
> This situation is common enough that it seems like something we aught to
> support out of the box.

Is the intention that the way this new mod_dir directive works is such
that SCRIPT_NAME as added by ap_add_cgi_vars() would equate to the URL
of the directory, or is it still going to end up having index.php on
the URL, like with when using rewrite rules to achieve the same thing?

It is a bit of pain that when using rewrite rules that you have to do
a fiddle to SCRIPT_NAME to avoid the index.php bit appearing if you
base URL reconstruction on SCRIPT_NAME.

Graham

Re: svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Posted by Rich Bowen <rb...@rcbowen.com>.
On Jun 16, 2009, at 18:43, William A. Rowe, Jr. wrote:

> William A. Rowe, Jr. wrote:
>>
>> This might be NotFoundHandler or for dir-not-file, ListingHandler.
>
> Sorry; not ListingHandler, but IndexHandler.
>
> But there is no point to a NotFoundHandler; the existing mechanics
> in ScriptAlias combined with PATH_INFO solve that problem already.
>
> I think the interest was in handling the directory resource URI and
> that would be an IndexHandler, absolutely.

The intent was to call a something (I'd call it a handler) for  
requests that don't correspond to a resource. This is to answer the  
frequent configuration:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [PT]

ie - if the request wasn't for a file, send the request directly to  
index.php (or index.pl, or wordpress.php, or whatever)

and variations thereof that occur in every PHP web app I install these  
days. This situation is common enough that it seems like something we  
aught to support out of the box.

--
In America, through pressure of conformity, there is freedom of  
choice, but nothing to choose from. (Peter Ustinov)


Re: svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
William A. Rowe, Jr. wrote:
> 
> This might be NotFoundHandler or for dir-not-file, ListingHandler.

Sorry; not ListingHandler, but IndexHandler.

But there is no point to a NotFoundHandler; the existing mechanics
in ScriptAlias combined with PATH_INFO solve that problem already.

I think the interest was in handling the directory resource URI and
that would be an IndexHandler, absolutely.

Re: svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Posted by Nick Kew <ni...@webthing.com>.
On Thu, 18 Jun 2009 18:57:54 +0200
Bob Ionescu <bo...@googlemail.com> wrote:

> 2009/6/17 Dan Poirier <po...@pobox.com>
> > It seems to me that "Default" is right - it implies what should be
> > done when no more explicit configuration applies.  E.g. DefaultType,
> > DefaultIcon, etc.
> >
> > Whether this is a "Handler" I'm not so sure of.
> 
> I'd call it DefaultMapping or so to avoid confusion with SetHandler.
> Usually, the therm "handler" is known to be somewhat file
> resource-independent unless you're using the Action directive and
> associate a specific cgi-script to a handler.
> 
> DefaultMapping /index.php
> AddHandler php_handler .php

+1

Makes sense to me.  DefaultHandler was from an earlier idea
on implementation, but test-driving that revealed a bunch of
gotchas that would've confused the hell out of users - hence
the switch to a clone of Directory index handling.

-- 
Nick Kew

Re: svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Posted by "Akins, Brian" <Br...@turner.com>.
On 6/18/09 12:57 PM, "Bob Ionescu" <bo...@googlemail.com> wrote:

> DefaultMapping /index.php
> AddHandler php_handler .php

Of course, though, php is only supported in fastcgi mode now.

Unrelated to the discussion, but, yes, I will keep saying this over and over
again until I quit seeing references to mod_php/libphp in apache2....

-- 
Brian Akins
Chief Operations Engineer
Turner Digital Media Technologies


Re: svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Posted by Bob Ionescu <bo...@googlemail.com>.
2009/6/17 Dan Poirier <po...@pobox.com>
> It seems to me that "Default" is right - it implies what should be done
> when no more explicit configuration applies.  E.g. DefaultType,
> DefaultIcon, etc.
>
> Whether this is a "Handler" I'm not so sure of.

I'd call it DefaultMapping or so to avoid confusion with SetHandler.
Usually, the therm "handler" is known to be somewhat file
resource-independent unless you're using the Action directive and
associate a specific cgi-script to a handler.

DefaultMapping /index.php
AddHandler php_handler .php

is more intuitive IMHO since the directive maps the request /foo to
/index.php if no corresponding resource was found in the filesystem
and no content handler was associated (e.g. via SetHandler).

Bob

Re: svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Posted by Rich Bowen <rb...@rcbowen.com>.
On Jun 17, 2009, at 08:10, Dan Poirier wrote:

> "William A. Rowe, Jr." <wr...@rowe-clan.net> writes:
>
>> DefaultHandler implies handling all content; not no-match content.
>
> It seems to me that "Default" is right - it implies what should be  
> done
> when no more explicit configuration applies.  E.g. DefaultType,
> DefaultIcon, etc.
>
> Whether this is a "Handler" I'm not so sure of.

Yes, I agree, Default. DefaultIcon is used when no other icon is  
indicated. DefaultType is used when no other type is indicated.  
DefaultHandler gets called when the requested URI doesn't correspond  
to an existing handler or resource.

--
If we only live,
We too will go to sea in a Sieve,---
   To the hills of the Chankly Bore!




Re: svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Posted by Dan Poirier <po...@pobox.com>.
"William A. Rowe, Jr." <wr...@rowe-clan.net> writes:

> DefaultHandler implies handling all content; not no-match content.

It seems to me that "Default" is right - it implies what should be done
when no more explicit configuration applies.  E.g. DefaultType,
DefaultIcon, etc.

Whether this is a "Handler" I'm not so sure of.

-- 
Dan Poirier <po...@pobox.com>


Re: svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
>  
> +  *) mod_dir: add DefaultHandler directive, to enable admin to specify
> +     an action to happen when a URL maps to no file, without resorting
> +     to ErrorDocument or mod_rewrite.  PR 47184 [Nick Kew]
> +

Ixnay on the irectiveday abuseway.

DefaultHandler implies handling all content; not no-match content.

This might be NotFoundHandler or for dir-not-file, ListingHandler.

Re: svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Posted by Ruediger Pluem <rp...@apache.org>.

On 06/16/2009 11:57 PM, niq@apache.org wrote:
> Author: niq
> Date: Tue Jun 16 21:57:25 2009
> New Revision: 785425
> 
> URL: http://svn.apache.org/viewvc?rev=785425&view=rev
> Log:
> Add DefaultHandler directive to mod_dir.
> PR 47184
> 
> Modified:
>     httpd/httpd/trunk/CHANGES
>     httpd/httpd/trunk/modules/mappers/mod_dir.c
> 
> 
> Modified: httpd/httpd/trunk/modules/mappers/mod_dir.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mappers/mod_dir.c?rev=785425&r1=785424&r2=785425&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/mappers/mod_dir.c (original)
> +++ httpd/httpd/trunk/modules/mappers/mod_dir.c Tue Jun 16 21:57:25 2009
> @@ -40,6 +40,7 @@
>  typedef struct dir_config_struct {
>      apr_array_header_t *index_names;
>      slash_cfg do_slash;
> +    const char *dflt;
>  } dir_config_rec;
>  
>  #define DIR_CMD_PERMS OR_INDEXES
> @@ -82,6 +83,9 @@
>  
>  static const command_rec dir_cmds[] =
>  {
> +    AP_INIT_TAKE1("DefaultHandler", ap_set_string_slot,
> +                  (void*)APR_OFFSETOF(dir_config_rec, dflt),
> +                  DIR_CMD_PERMS, "Set a default handler"),
>      AP_INIT_RAW_ARGS("DirectoryIndex", add_index, NULL, DIR_CMD_PERMS,
>                      "a list of file names"),
>      AP_INIT_FLAG("DirectorySlash", configure_slash, NULL, DIR_CMD_PERMS,
> @@ -107,9 +111,53 @@
>      new->index_names = add->index_names ? add->index_names : base->index_names;
>      new->do_slash =
>          (add->do_slash == SLASH_UNSET) ? base->do_slash : add->do_slash;
> +    new->dflt = add->dflt ? add->dflt : base->dflt;
>      return new;
>  }
>  
> +static int fixup_dflt(request_rec *r)
> +{
> +    dir_config_rec *d = ap_get_module_config(r->per_dir_config, &dir_module);
> +    const char *name_ptr;
> +    request_rec *rr;
> +    int error_notfound = 0;
> +    if ((r->finfo.filetype != APR_NOFILE) || (r->handler != NULL)) {
> +        return DECLINED;
> +    }

Doesn't this cause issues when we have configured several different index files via
DirectoryIndex and the first one of these is not present. I guess in this case the
appropriate subrequest should return NOT_FOUND which it does not do here, correct?

Regards

Rüdiger


Re: svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Posted by Nick Kew <ni...@webthing.com>.
On 16 Jun 2009, at 23:21, André Malo wrote:

> * niq@apache.org wrote:
>
>>  static void register_hooks(apr_pool_t *p)
>>  {
>>      ap_hook_fixups(fixup_dir,NULL,NULL,APR_HOOK_LAST);
>> +    ap_hook_fixups(fixup_dflt,NULL,NULL,APR_HOOK_LAST);
>>  }
>>
>>  module AP_MODULE_DECLARE_DATA dir_module = {
>
> Without further checking: should we ensure the fixup_dflt is  
> executed after
> fixup_dir? Or is it already (Looks actually random to me)? Maybe it  
> should
> be a late handler instead?

The order is unimportant.  The circumstances under which the two  
functions
do anything other than return an immediate DECLINED are mutually  
exclusive.

I haven't thought through why fixup_dir runs when it does, but I'm
reasonably confident that what works for DirectoryIndex will work fine
for its young cousin DefaultHandler (or whatever Bill changes that to).

-- 
Nick Kew

Re: svn commit: r785425 - in /httpd/httpd/trunk: CHANGES modules/mappers/mod_dir.c

Posted by André Malo <nd...@perlig.de>.
* niq@apache.org wrote:

>  static void register_hooks(apr_pool_t *p)
>  {
>      ap_hook_fixups(fixup_dir,NULL,NULL,APR_HOOK_LAST);
> +    ap_hook_fixups(fixup_dflt,NULL,NULL,APR_HOOK_LAST);
>  }
>
>  module AP_MODULE_DECLARE_DATA dir_module = {

Without further checking: should we ensure the fixup_dflt is executed after 
fixup_dir? Or is it already (Looks actually random to me)? Maybe it should 
be a late handler instead?

nd
-- 
Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
Ook! Ook? Ook. Ook? Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook. Ook.
Ook. Ook. Ook. Ook. Ook? Ook. Ook! Ook! Ook? Ook! Ook. Ook? Ook. Ook.
Ook. Ook. Ook. Ook. Ook! Ook. Ook! Ook! Ook! Ook!           Ook! Ook.