You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Gary C. New" <ga...@yahoo.com> on 2004/02/11 03:38:09 UTC
Request Object Work Flow - is_initial_req, is_main, main
I am very near in completing a module that allows one to dynamically
re-map Apache's DocumentRoot directive based on a given URI.
I've been able to get past several obstacles, but am having a very
difficult time understanding the request object work flow.
My problem seems to be due to subrequests not being mapped properly.
The initial request seems to map as it should, but subrequests are
randomly mapped or not mapped at all. I can reload the same page and
get different subrequests to map, while the previously working
subrequests no longer map.
My only thought is that it is due to my lack of understanding of the
request object work flow.
Any basic pointers or examples that could give me a better understanding
of this process would be greatly appreciated.
Sincerely,
Gary
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: Request Object Work Flow - is_initial_req, is_main, main
Posted by "Gary C. New" <ga...@yahoo.com>.
Geoffrey,
Once again, I appreciate your informative responses.
I've decided to abandon the idea in favor of using mod_rewrite.
I discovered the back reference capability in mod_rewrite and combined
with some php trickery have been able to produce the desired shared ssl
effect.
Thank you again for your wonderful assistance.
Respectfully,
Gary
Geoffrey Young wrote:
>
> Gary C. New wrote:
>
>>I am very near in completing a module that allows one to dynamically
>>re-map Apache's DocumentRoot directive based on a given URI.
>>
>>I've been able to get past several obstacles, but am having a very
>>difficult time understanding the request object work flow.
>>
>>My problem seems to be due to subrequests not being mapped properly.
>>
>>The initial request seems to map as it should, but subrequests are
>>randomly mapped or not mapped at all. I can reload the same page and
>>get different subrequests to map, while the previously working
>>subrequests no longer map.
>
>
> this is a really difficult thing you are trying to do.
>
> basically, DocumentRoot is a property of the server - if you modify it the
> changes are propagated for all later requests to the same Apache child. so,
> if you want to mess with it you need to be sure to set it back before the
> next request starts.
>
> so, say you have a request where you change the DocumentRoot and schedule a
> cleanup to reset it. now, in the middle of that request you have a
> subrequest. this subrequest probably thinks that the original DocumentRoot
> is the one you just set in the main request, etc.
>
> messing around with server attributes on a per-request level is tricky. in
> general, I'd suggest against it - the only reason I've ever seen where it is
> required to alter the DocumentRoot is for supporting FrontPage extensions.
> other than that, there are ways around coding a dependency around
> $ENV{DOCUMENT_ROOT}, such as coherent relative paths - it's is supposed to
> be private to Apache core anyway :)
>
> that said, you might be able to add some logic so that the the real
> DocumentRoot is set in $r->notes via
>
> $r->notes(?REAL_DOCROOT => $r->document_root) if $r->is_initial_req;
>
> then for restoration everyone looks at $r->main->notes instead of relying on
> what is in $r->document_root.
>
> as an alternative, you could always just place the value you want for your
> new DocumentRoot in notes from a fixup handler, then crack open
> util_script.c in the apache 1.3 sources, and alter ap_add_common_vars to use
> your notes value for DOCUMENT_ROOT instead of ap_document_root. something
> like this (untested)
>
> Index: src/main/util_script.c
> ===================================================================
> RCS file: /home/cvspublic/apache-1.3/src/main/util_script.c,v
> retrieving revision 1.168
> diff -u -r1.168 util_script.c
> --- src/main/util_script.c 1 Jan 2004 13:32:54 -0000 1.168
> +++ src/main/util_script.c 11 Feb 2004 15:08:06 -0000
> @@ -203,6 +203,7 @@
> array_header *hdrs_arr = ap_table_elts(r->headers_in);
> table_entry *hdrs = (table_entry *) hdrs_arr->elts;
> int i;
> + char *docroot;
>
> /* use a temporary table which we'll overlap onto
> * r->subprocess_env later
> @@ -290,7 +291,10 @@
> ap_table_addn(e, "REMOTE_HOST", host);
> }
> ap_table_addn(e, "REMOTE_ADDR", c->remote_ip);
> - ap_table_addn(e, "DOCUMENT_ROOT", ap_document_root(r)); /* Apache */
> + if (! (docroot = ap_table_get(r->notes, "REAL_DOCROOT")) ) {
> + docroot = ap_document_root(r);
> + }
> + ap_table_addn(e, "DOCUMENT_ROOT", docroot); /* Apache */
> ap_table_addn(e, "SERVER_ADMIN", s->server_admin); /* Apache */
> ap_table_addn(e, "SCRIPT_FILENAME", r->filename); /* Apache */
>
>
> HTH
>
> --Geoff
>
>
--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: Request Object Work Flow - is_initial_req, is_main, main
Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi there,
On Wed, 11 Feb 2004, Geoffrey Young wrote:
> > I am very near in completing a module that allows one to dynamically
> > re-map Apache's DocumentRoot directive based on a given URI.
>
> this is a really difficult thing you are trying to do.
Did anyone find the problem to this solution?
:)
73,
Ged.
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html
Re: Request Object Work Flow - is_initial_req, is_main, main
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
Gary C. New wrote:
> I am very near in completing a module that allows one to dynamically
> re-map Apache's DocumentRoot directive based on a given URI.
>
> I've been able to get past several obstacles, but am having a very
> difficult time understanding the request object work flow.
>
> My problem seems to be due to subrequests not being mapped properly.
>
> The initial request seems to map as it should, but subrequests are
> randomly mapped or not mapped at all. I can reload the same page and
> get different subrequests to map, while the previously working
> subrequests no longer map.
this is a really difficult thing you are trying to do.
basically, DocumentRoot is a property of the server - if you modify it the
changes are propagated for all later requests to the same Apache child. so,
if you want to mess with it you need to be sure to set it back before the
next request starts.
so, say you have a request where you change the DocumentRoot and schedule a
cleanup to reset it. now, in the middle of that request you have a
subrequest. this subrequest probably thinks that the original DocumentRoot
is the one you just set in the main request, etc.
messing around with server attributes on a per-request level is tricky. in
general, I'd suggest against it - the only reason I've ever seen where it is
required to alter the DocumentRoot is for supporting FrontPage extensions.
other than that, there are ways around coding a dependency around
$ENV{DOCUMENT_ROOT}, such as coherent relative paths - it's is supposed to
be private to Apache core anyway :)
that said, you might be able to add some logic so that the the real
DocumentRoot is set in $r->notes via
$r->notes(?REAL_DOCROOT => $r->document_root) if $r->is_initial_req;
then for restoration everyone looks at $r->main->notes instead of relying on
what is in $r->document_root.
as an alternative, you could always just place the value you want for your
new DocumentRoot in notes from a fixup handler, then crack open
util_script.c in the apache 1.3 sources, and alter ap_add_common_vars to use
your notes value for DOCUMENT_ROOT instead of ap_document_root. something
like this (untested)
Index: src/main/util_script.c
===================================================================
RCS file: /home/cvspublic/apache-1.3/src/main/util_script.c,v
retrieving revision 1.168
diff -u -r1.168 util_script.c
--- src/main/util_script.c 1 Jan 2004 13:32:54 -0000 1.168
+++ src/main/util_script.c 11 Feb 2004 15:08:06 -0000
@@ -203,6 +203,7 @@
array_header *hdrs_arr = ap_table_elts(r->headers_in);
table_entry *hdrs = (table_entry *) hdrs_arr->elts;
int i;
+ char *docroot;
/* use a temporary table which we'll overlap onto
* r->subprocess_env later
@@ -290,7 +291,10 @@
ap_table_addn(e, "REMOTE_HOST", host);
}
ap_table_addn(e, "REMOTE_ADDR", c->remote_ip);
- ap_table_addn(e, "DOCUMENT_ROOT", ap_document_root(r)); /* Apache */
+ if (! (docroot = ap_table_get(r->notes, "REAL_DOCROOT")) ) {
+ docroot = ap_document_root(r);
+ }
+ ap_table_addn(e, "DOCUMENT_ROOT", docroot); /* Apache */
ap_table_addn(e, "SERVER_ADMIN", s->server_admin); /* Apache */
ap_table_addn(e, "SCRIPT_FILENAME", r->filename); /* Apache */
HTH
--Geoff
--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html