On 4/14/23 4:07 PM, minfrin@apache.org wrote:
> Author: minfrin
> Date: Fri Apr 14 14:07:49 2023
> New Revision: 1909137
>
> URL: http://svn.apache.org/viewvc?rev=1909137&view=rev
> Log:
> mod_alias: When an alias is declared inside a Location, make sure
> the balance of the URL is preserved to match the alias declared
> outside a location. Fixes an error where all requests are mapped
> to the root of the location.
>
> Modified:
> httpd/httpd/trunk/CHANGES
> httpd/httpd/trunk/modules/mappers/mod_alias.c
>
> Modified: httpd/httpd/trunk/CHANGES
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1909137&r1=1909136&r2=1909137&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/CHANGES [utf-8] (original)
> +++ httpd/httpd/trunk/CHANGES [utf-8] Fri Apr 14 14:07:49 2023
> @@ -1,6 +1,11 @@
> -*- coding: utf-8 -*-
> Changes with Apache 2.5.1
>
> + *) mod_alias: When an alias is declared inside a Location, make sure
> + the balance of the URL is preserved to match the alias declared
> + outside a location. Fixes an error where all requests are mapped
> + to the root of the location. [Graham Leggett]
> +
> *) core: Be explicit if an enclosing directive contains a path or a
> regex. [Graham Leggett]
>
>
> Modified: httpd/httpd/trunk/modules/mappers/mod_alias.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mappers/mod_alias.c?rev=1909137&r1=1909136&r2=1909137&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/mappers/mod_alias.c (original)
> +++ httpd/httpd/trunk/modules/mappers/mod_alias.c Fri Apr 14 14:07:49 2023
> @@ -59,6 +59,7 @@ typedef struct {
> unsigned int redirect_set:1;
> apr_array_header_t *redirects;
> const ap_expr_info_t *alias;
> + const char *alias_fake;
> char *handler;
> const ap_expr_info_t *redirect;
> int redirect_status; /* 301, 302, 303, 410, etc */
> @@ -113,6 +114,7 @@ static void *merge_alias_dir_config(apr_
> a->redirects = apr_array_append(p, overrides->redirects, base->redirects);
>
> a->alias = (overrides->alias_set == 0) ? base->alias : overrides->alias;
> + a->alias_fake = (overrides->alias_set == 0) ? base->alias_fake : overrides->alias_fake;
> a->handler = (overrides->alias_set == 0) ? base->handler : overrides->handler;
> a->alias_set = overrides->alias_set || base->alias_set;
>
> @@ -220,6 +222,9 @@ static const char *add_alias(cmd_parms *
> NULL);
> }
>
> + if (!cmd->regex) {
> + dirconf->alias_fake = cmd->path;
> + }
> dirconf->handler = cmd->info;
> dirconf->alias_set = 1;
>
> @@ -438,6 +443,17 @@ static char *try_alias(request_rec *r)
> return PREGSUB_ERROR;
> }
>
> + if (dirconf->alias_fake) {
> + int l;
> +
> + l = alias_matches(r->uri, dirconf->alias_fake);
> +
> + if (l > 0) {
> + ap_set_context_info(r, dirconf->alias_fake, found);
> + found = apr_pstrcat(r->pool, found, r->uri + l, NULL);
> + }
> + }
> +
Would that break configs like
<Location /someplace>
Alias /filesystemprefix/%{HTTP:X-example-header}
</Location>
where the expression evaluation determines the complete filesystem path without adding the remainder of the URL?
I admit that the above looks like a strange setup and is probably a bad example, but the parameter to Alias could be an arbitrary
complex expression that evaluates to the final filesystem resource (like AliasMatch). Wouldn't we need a kind of way to figure out
if the users wants the remainder of the URI added or not even if we do not use a regular expression in the surrounding Location block?
Regards
Rüdiger
> Author: minfrin
> Date: Fri Apr 14 14:07:49 2023
> New Revision: 1909137
>
> URL: http://svn.apache.org/viewvc?rev=1909137&view=rev
> Log:
> mod_alias: When an alias is declared inside a Location, make sure
> the balance of the URL is preserved to match the alias declared
> outside a location. Fixes an error where all requests are mapped
> to the root of the location.
>
> Modified:
> httpd/httpd/trunk/CHANGES
> httpd/httpd/trunk/modules/mappers/mod_alias.c
>
> Modified: httpd/httpd/trunk/CHANGES
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1909137&r1=1909136&r2=1909137&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/CHANGES [utf-8] (original)
> +++ httpd/httpd/trunk/CHANGES [utf-8] Fri Apr 14 14:07:49 2023
> @@ -1,6 +1,11 @@
> -*- coding: utf-8 -*-
> Changes with Apache 2.5.1
>
> + *) mod_alias: When an alias is declared inside a Location, make sure
> + the balance of the URL is preserved to match the alias declared
> + outside a location. Fixes an error where all requests are mapped
> + to the root of the location. [Graham Leggett]
> +
> *) core: Be explicit if an enclosing directive contains a path or a
> regex. [Graham Leggett]
>
>
> Modified: httpd/httpd/trunk/modules/mappers/mod_alias.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/mappers/mod_alias.c?rev=1909137&r1=1909136&r2=1909137&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/mappers/mod_alias.c (original)
> +++ httpd/httpd/trunk/modules/mappers/mod_alias.c Fri Apr 14 14:07:49 2023
> @@ -59,6 +59,7 @@ typedef struct {
> unsigned int redirect_set:1;
> apr_array_header_t *redirects;
> const ap_expr_info_t *alias;
> + const char *alias_fake;
> char *handler;
> const ap_expr_info_t *redirect;
> int redirect_status; /* 301, 302, 303, 410, etc */
> @@ -113,6 +114,7 @@ static void *merge_alias_dir_config(apr_
> a->redirects = apr_array_append(p, overrides->redirects, base->redirects);
>
> a->alias = (overrides->alias_set == 0) ? base->alias : overrides->alias;
> + a->alias_fake = (overrides->alias_set == 0) ? base->alias_fake : overrides->alias_fake;
> a->handler = (overrides->alias_set == 0) ? base->handler : overrides->handler;
> a->alias_set = overrides->alias_set || base->alias_set;
>
> @@ -220,6 +222,9 @@ static const char *add_alias(cmd_parms *
> NULL);
> }
>
> + if (!cmd->regex) {
> + dirconf->alias_fake = cmd->path;
> + }
> dirconf->handler = cmd->info;
> dirconf->alias_set = 1;
>
> @@ -438,6 +443,17 @@ static char *try_alias(request_rec *r)
> return PREGSUB_ERROR;
> }
>
> + if (dirconf->alias_fake) {
> + int l;
> +
> + l = alias_matches(r->uri, dirconf->alias_fake);
> +
> + if (l > 0) {
> + ap_set_context_info(r, dirconf->alias_fake, found);
> + found = apr_pstrcat(r->pool, found, r->uri + l, NULL);
> + }
> + }
> +
Would that break configs like
<Location /someplace>
Alias /filesystemprefix/%{HTTP:X-example-header}
</Location>
where the expression evaluation determines the complete filesystem path without adding the remainder of the URL?
I admit that the above looks like a strange setup and is probably a bad example, but the parameter to Alias could be an arbitrary
complex expression that evaluates to the final filesystem resource (like AliasMatch). Wouldn't we need a kind of way to figure out
if the users wants the remainder of the URI added or not even if we do not use a regular expression in the surrounding Location block?
Regards
Rüdiger