You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by André Warnier <aw...@ice-sa.com> on 2012/11/12 18:19:55 UTC

question on sub-requests

Hi.

context: Apache2.x, mod_perl 2.x

In response to some request URLs, I have to compose a response structured as follows :

- a html frameset document with two frames
- in the 1st frame, the result of another HTTP request to the same Apache server.
   This URI of this HTTP request is created by "mangling" the original request URL somewhat.
- in the 2d frame, the content of the HTML file corresponding to the original request URI.

For example, if the original request URI was something like : "/abc/def/ghi.html", then
   - the top frame should contain the (html) output of a request to 
"/cgi-bin/mangle.pl?arg=ghi"
   - the bottom frame should contain the content of the originally-requested 
"/abc/def/ghi.html" URI (which is a static file).

I am thinking of doing this by :
- creating a mod_perl ResponseHandler
- having this response handler make a first sub-request to the 
"/cgi-bin/mangle.pl?arg=ghi" URI, grabbing the content of the response to that 
sub-request, and insert it into the first <frame> of the output <frameset> document.
- having the response handler do a lookup_uri of the original URI, get the resulting 
filename, reading the file and insert its content into the second <frame> of the output 
<frameset> document.

My 1st question is : is the above a valid plan, or is there something fundamentally wrong 
with this approach ?

My 2d question is : looking at the Apache2::SubRequest documentation, I do not see a clear 
way of getting the response content of a subrequest.  For example, the run() method 
explanation seems to indicate that the response content is sent directly to the client.
Am I missing something ?

TIA


Re: question on sub-requests

Posted by Torsten Förtsch <to...@gmx.net>.
On 11/14/2012 03:53 PM, André Warnier wrote:
> The tidbit above makes me think about a possibility to solve another
> issue that happens from time to time : some users browsers that are NOT
> refreshing their copies of stylesheets or javascript libraries, even
> though they have been modified.
> Not all users know how to clear their browser cache (and some cannot
> because of policies). Maybe this offers a way to solve that.  Need to
> think about it.

much simpler, remove the corresponding If-* input headers with mod_perl
or mod_headers.

Torsten

Re: question on sub-requests

Posted by André Warnier <aw...@ice-sa.com>.
Torsten Förtsch wrote:
> On 11/14/2012 02:48 PM, André Warnier wrote:
>> I my particular case, the sendfile() solution above works fine, because
>> I am sure in this case that no additional processing needs to take place
>> on those static pages.
> 
> What I meant in particular was the HTTP code 304 generation. With your
> solution the browser will always get a fresh copy even if the cache is
> still valid.

Ok, get it.  So I will use the internal_redirect / initial_req version.

The tidbit above makes me think about a possibility to solve another issue that happens 
from time to time : some users browsers that are NOT refreshing their copies of 
stylesheets or javascript libraries, even though they have been modified.
Not all users know how to clear their browser cache (and some cannot because of policies). 
Maybe this offers a way to solve that.  Need to think about it.


Re: question on sub-requests

Posted by Torsten Förtsch <to...@gmx.net>.
On 11/14/2012 02:48 PM, André Warnier wrote:
> I my particular case, the sendfile() solution above works fine, because
> I am sure in this case that no additional processing needs to take place
> on those static pages.

What I meant in particular was the HTTP code 304 generation. With your
solution the browser will always get a fresh copy even if the cache is
still valid.

> About returning DECLINED in a ResponseHandler : that works fine, and
> apparently has the effect of Apache serving the resource using it's
> default handler (or, I suppose, any other alternative response handler
> that may be chained).  This is consistent with the fact that a response
> handler is of type
> 
> quote
> RUN_FIRST

That's why I thought returning DECLINED should work. If you want to
switch to dedicated handler other than the default one I think you can
set it via $r->handler(newhandler). But in this case you have to hope
that the new handler is further down the handler chain. Modperl
registers its 2 response handlers with APR_HOOK_MIDDLE. So, it may
depend on the LoadModule order whether the modperl handler comes first
or newhandler.

Torsten

Re: question on sub-requests

Posted by André Warnier <aw...@ice-sa.com>.
Torsten Förtsch wrote:
> On 11/13/2012 07:17 PM, André Warnier wrote:
>> I didn't want to take too much time of anyone before, which is why I
>> somewhat oversimplified the issue.  But considering the traffic on the
>> lis os low, maybe you want to hear the whole story after all.
>>
>> The basic case is this : a bit aside from our usual professional
>> activities and for a friend, we run a website which is basically a shop
>> with hundreds of individual items which people can view and buy.  (I
>> will provide the URL privately to anyone who is more interested. It's a
>> cute shop.)
>>
>> The pages corresponding to these individual items, at the moment, are
>> individual static pages in multiple sub-directories, and there are quite
>> a lot of them.  The friend creates and maintains these static pages
>> herself; she is an artist rather than a programmer, so she can handle an
>> html editor (which she does rather well) to edit static pages and test
>> them on her PC before copying them to the server, but we cannot ask her
>> to handle any kind of "template" pages or the like.
>> Add to this that the basic logic of the website and the design and
>> techniques used date back from some 10 years ago, have been patched and
>> repatched several times over several years, and are rather bad.
>>
>> Now there is a requirement that, instead of being just static pages,
>> each of these pages should in addition contain a <form> with some
>> specific item-related information, allowing to buy these items on-line
>> (so it cannot be done just with an include or a stylesheet).
> 
> Have you considered to patch the files automatically? CPAN has a bunch
> of modules that can parse also quite bad/old HTML (with missing </p> or
> </li> and the stuff).
> 
> You could for example keep the original files in one directory tree and
> set up a process that waits for changes there either by scanning it on a
> regular basis or even by using inotify (there is a cron-like daemon that
> is made just for this kind of monitoring. I think it's called incron or
> so. Anyway, there is plenty of support for inotify on CPAN.)
> 
> Now, if anything changes the daemon can start a program that parses the
> HTML, inserts the form and writes the result to another directory which
> is your DocumentRoot. On the way it could also call 'git commit'. And
> now you have a simple content management system almost for free.
> 
>> What I am trying to achieve, without having to edit each of these
>> individual hundreds of pages, or changing the links to these pages, or
>> change the basic design of the application (because there is no budget
>> for that), is to find a clever way on the server side
>> to respond to a normal "/Shop_xxx/def/xyz.html" URL of one of these
>> pages, to combine into one response both the required <form>, and the
>> content of the existing unmodified static page.  I also do not want to
>> parse the html on-the-fly and insert a <form> right into it, because the
>> html that she creates with her (T-online) editor is rather bad to start
>> with, and I have no guarantee that the result would be pleasing.
>>
>> So that was the reason to think of the <frameset> solution, whereby in
>> response to the initial request for "/Shop_xxx/def/xyz.html", I would
>> respond with a first <frame> containing the form (generated by a
>> back-end application, and depending on the item), and a second <frame>
>> containing her artfully-crafted static page describing that item in all
>> its glory.
>>
>> The static pages in question are in several subdirectories of
>> DocumentRoot, and at different levels.  Fortunately, all the top
>> sub-directories names start with "/Shop_" (after which there can be
>> "Quilts" or "Babydecken" and things like that, and a variable hierarchy
>> of sub-directories containing html files and jpg images and the like.
>>
>> So I have this configured :
>> <LocationMatch "^/Shop_">
>>   sethandler modperl
>>   PerlResponseHandler My::ShopResponse
>>   ...
>> </LocationMatch>
>>
>> As a result in part of the previous communications on this list, this
>> PerlResponseHandler
>> does more or less what I want, except one remaining problem which I am
>> trying to resolve right now :
>> In response to an initial request for "/Shop_xxx/def/xyz.html", the
>> handler generates a
>> <frameset> document as such :
>> <html>
>> <frameset rows="100,*">
>>   <frame name="top_frame" src="..the URI which generates the form.." /> 
>> (1)
>>   <frame name="bottom_frame" src="/Shop_xxx/def/xyz.html.shop" />  (2)
>> </frameset>
>> </html>
>>
>> (1) for the dynamically-generated html <form> document
>> (2) for the static existing page
>>
>> Because the second frame's URI also starts with "/Shop_", when the
>> browser requests this frame, the same ResponseHandler is called.
>> The handler examines the URL and sees that it ends in ".shop" (instead
>> of ".html").
>> So it knows that this time, it should not send another frameset, but
>> instead it should strip the trailing ".shop" and deliver, as is, the
>> content of the static document "/Shop_xxx/def/xyz.html".
>>
>> But, how do I tell it to do that ?
>> I have tried :
>>   my $uri = $r->uri();
>>   if ($uri =~ m!\/([^/]+\.htm[l]?\.shop)$!i) {
>>     $uri =~ s/\.shop$//; # strip the trailing ".shop"
>>     $r->internal_redirect($uri);
>>         return Apache2::Const::OK ;
>>   }
>>
>> and also :
>>
>>   my $uri = $r->uri();
>>   if ($uri =~ m!\/([^/]+\.htm[l]?\.shop)$!i) {
>>     $uri =~ s/\.shop$//; # strip the trailing ".shop"
>>     my $subr = $r->lookup_uri($uri);
>>     $subr->run();
>>         return Apache2::Const::OK ;
>>   }
>>
>> but both of those result in a loop : they end up requesting
>> "/Shop_xxx/def/xyz.html", which hits the same Location, which runs the
>> same handler, which then produces the frameset, and so on.
> 
> Here is how the cycle goes:
> 
> 1) The server gets a request for /Shop_xxx/def/xyz.html, skips the
> if-branch and generates the frameset.
> 
> 2) The bottom frame generates another request for
> /Shop_xxx/def/xyz.html.shop. It enters the if-branch and issues a
> subrequest or an internal redirect for /Shop_xxx/def/xyz.html.
> 
> 3) The subeq/redir enters the handler again. Now it avoids the if-branch
> because it does not match /\.shop$/. So it spits out the frameset.
> 
> 4) goto 2) by means of the browser
> 
> How to break the loop? Instead (or inside) of the LocationMatch above use:
> 
> PerlFixupHandler "sub {                                         \
>   use Apache2::RequestUtil ();                                  \
>   use Apache2::RequestRec ();                                   \
>   use Apache2::Const -compile=>qw/DECLINE/;                     \
>   my ($r)=@_;                                                   \
>   if( $r->is_initial_req ) {                                    \
>     $r->handler('modperl');                                     \
>     $r->set_handlers(PerlResponseHandler=>'My::ShopResponse');  \
>   }                                                             \
>   return Apache2::Const::DECLINED;                              \
> }"
> 
> Then step 3) reads:
> 
> 3) The subreq/redir enters the request cycle again. The if-branch of
> fixup handler is skipped because the request is not initial. Hence, the
> PerlResponseHandler is skipped completely and the default handler sends
> the document.
> 
> You can achieve a similar effect with mod_rewrite. It has IS_SUBREQ
> available in RewriteCond. But I don't know if that also checks for
> !$r->prev.
> 
> You can also try to modify your Response handler to decline if
> !$r->is_initial_req:
> 
>   my $uri = $r->uri();
>   if ($uri =~ s!(/[^/]+\.html?)\.shop$!$1!i) {
>     $r->internal_redirect($uri);
>     return Apache2::Const::OK ;
>   }
>   return Apache2::Const::DECLINE unless $r->is_initial_req;
> 
> I am not sure if that works. I think I have never tried to return
> DECLINED from a response handler.
> 
>> So how do I tell Apache/mod_perl that this time "I mean it", and that it
>> should directly deliver the requested file, without re-running the whole
>> cycle ?
>>
>> I can of course request the corresponding filename() and deliver it
>> myself (perhaps with sendfile()), but that does not seem to be the most
>> elegant way of doing this. Or is it ?
>>
>> Oh, and I'd like it elegant, but I would prefer not having to introduce
>> a PerlFixupHandler or a PerlOutputFilter or Javascript, and do it all
>> within this ResponseHandler.  That's because I have colleagues who know
>> even less about mod_perl than I do, and I'd like to leave them something
>> simple to deal with in support and maintenance for another 10 years.
>>
>> ...
>>
>> Aside : I just tried
>>
>>   my $uri = $r->uri();
>>   if ($uri =~ m!\/([^/]+\.htm[l]?\.shop)$!i) {
>>     $uri =~ s/\.shop$//; # strip the trailing ".shop"
>>     my $subr = $r->lookup_uri($uri);
>>     $r->sendfile($subr->filename());
>>         return Apache2::Const::OK ;
>>   }
>>
>> and that works.  So I guess that /is/ the right solution here.
> 
> No, it's not.
> 
> The default handler does a bit more than just send $r->filename. For you
> it may work but it won't in the general case. See default_handler() in
> server/core.c.
> 
> Torsten
> 
> 
Hi Torsten.

Thanks for all your insightful and informative answers.

I my particular case, the sendfile() solution above works fine, because I am sure in this 
case that no additional processing needs to take place on those static pages.
But (even without checking the source of default_handler()) I understand that there may be 
cases where it wouldn't, and appreciate your tips for the future (and see below).

About returning DECLINED in a ResponseHandler : that works fine, and apparently has the 
effect of Apache serving the resource using it's default handler (or, I suppose, any other 
alternative response handler that may be chained).  This is consistent with the fact that 
a response handler is of type

quote
RUN_FIRST

Handlers of the type RUN_FIRST will be executed in the order they have been registered 
until the first handler that returns something other than Apache2::Const::DECLINED. If the 
return value is Apache2::Const::DECLINED, the next handler in the chain will be run. If 
the return value is Apache2::Const::OK the next phase will start. In all other cases the 
execution will be aborted.
unquote

As to the "initial vs subrequest" test : I have replaced my code section by yours above :

   if ($uri =~ s!(/[^/]+\.html?)\.shop$!$1!i) {
     $r->internal_redirect($uri);
     return Apache2::Const::OK ;
   }
   return Apache2::Const::DECLINED unless $r->is_initial_req;

and it is my pleasure to confirm that it works, and does avoid the "fractal" loop
(and it is also more elegant than mine).

About the option of pre-processing the html files : I had thought of that before too, and 
in fact the main reason for introducing this ResponseHandler was to replace a previous 
procedure that was doing something similar (processing all the html files coming from that 
less-than-optimal html editor, with a "cleanup" perl script).
But I ended up having to process so many "special cases" that in the end I thought it was 
just easier to deliver the static pages "as is", and let our friend correct them manually 
if they don't look exactly the way she wants.  Sometimes, less is more.

What should really happen with that website is a complete redesign, using the more modern 
techniques we're using nowadays with our other websites (TT2 e.g.).  But there is no 
budget for that, so this nth patch will have to do for now.

Thanks to all anyway.
This list is not very chatty, but always very helpful.
And I am a real mod_perl fan.  It is an incredibly powerful tool.


Re: question on sub-requests

Posted by Torsten Förtsch <to...@gmx.net>.
On 11/13/2012 07:17 PM, André Warnier wrote:
> I didn't want to take too much time of anyone before, which is why I
> somewhat oversimplified the issue.  But considering the traffic on the
> lis os low, maybe you want to hear the whole story after all.
> 
> The basic case is this : a bit aside from our usual professional
> activities and for a friend, we run a website which is basically a shop
> with hundreds of individual items which people can view and buy.  (I
> will provide the URL privately to anyone who is more interested. It's a
> cute shop.)
> 
> The pages corresponding to these individual items, at the moment, are
> individual static pages in multiple sub-directories, and there are quite
> a lot of them.  The friend creates and maintains these static pages
> herself; she is an artist rather than a programmer, so she can handle an
> html editor (which she does rather well) to edit static pages and test
> them on her PC before copying them to the server, but we cannot ask her
> to handle any kind of "template" pages or the like.
> Add to this that the basic logic of the website and the design and
> techniques used date back from some 10 years ago, have been patched and
> repatched several times over several years, and are rather bad.
> 
> Now there is a requirement that, instead of being just static pages,
> each of these pages should in addition contain a <form> with some
> specific item-related information, allowing to buy these items on-line
> (so it cannot be done just with an include or a stylesheet).

Have you considered to patch the files automatically? CPAN has a bunch
of modules that can parse also quite bad/old HTML (with missing </p> or
</li> and the stuff).

You could for example keep the original files in one directory tree and
set up a process that waits for changes there either by scanning it on a
regular basis or even by using inotify (there is a cron-like daemon that
is made just for this kind of monitoring. I think it's called incron or
so. Anyway, there is plenty of support for inotify on CPAN.)

Now, if anything changes the daemon can start a program that parses the
HTML, inserts the form and writes the result to another directory which
is your DocumentRoot. On the way it could also call 'git commit'. And
now you have a simple content management system almost for free.

> What I am trying to achieve, without having to edit each of these
> individual hundreds of pages, or changing the links to these pages, or
> change the basic design of the application (because there is no budget
> for that), is to find a clever way on the server side
> to respond to a normal "/Shop_xxx/def/xyz.html" URL of one of these
> pages, to combine into one response both the required <form>, and the
> content of the existing unmodified static page.  I also do not want to
> parse the html on-the-fly and insert a <form> right into it, because the
> html that she creates with her (T-online) editor is rather bad to start
> with, and I have no guarantee that the result would be pleasing.
> 
> So that was the reason to think of the <frameset> solution, whereby in
> response to the initial request for "/Shop_xxx/def/xyz.html", I would
> respond with a first <frame> containing the form (generated by a
> back-end application, and depending on the item), and a second <frame>
> containing her artfully-crafted static page describing that item in all
> its glory.
> 
> The static pages in question are in several subdirectories of
> DocumentRoot, and at different levels.  Fortunately, all the top
> sub-directories names start with "/Shop_" (after which there can be
> "Quilts" or "Babydecken" and things like that, and a variable hierarchy
> of sub-directories containing html files and jpg images and the like.
> 
> So I have this configured :
> <LocationMatch "^/Shop_">
>   sethandler modperl
>   PerlResponseHandler My::ShopResponse
>   ...
> </LocationMatch>
> 
> As a result in part of the previous communications on this list, this
> PerlResponseHandler
> does more or less what I want, except one remaining problem which I am
> trying to resolve right now :
> In response to an initial request for "/Shop_xxx/def/xyz.html", the
> handler generates a
> <frameset> document as such :
> <html>
> <frameset rows="100,*">
>   <frame name="top_frame" src="..the URI which generates the form.." /> 
> (1)
>   <frame name="bottom_frame" src="/Shop_xxx/def/xyz.html.shop" />  (2)
> </frameset>
> </html>
> 
> (1) for the dynamically-generated html <form> document
> (2) for the static existing page
> 
> Because the second frame's URI also starts with "/Shop_", when the
> browser requests this frame, the same ResponseHandler is called.
> The handler examines the URL and sees that it ends in ".shop" (instead
> of ".html").
> So it knows that this time, it should not send another frameset, but
> instead it should strip the trailing ".shop" and deliver, as is, the
> content of the static document "/Shop_xxx/def/xyz.html".
> 
> But, how do I tell it to do that ?
> I have tried :
>   my $uri = $r->uri();
>   if ($uri =~ m!\/([^/]+\.htm[l]?\.shop)$!i) {
>     $uri =~ s/\.shop$//; # strip the trailing ".shop"
>     $r->internal_redirect($uri);
>         return Apache2::Const::OK ;
>   }
> 
> and also :
> 
>   my $uri = $r->uri();
>   if ($uri =~ m!\/([^/]+\.htm[l]?\.shop)$!i) {
>     $uri =~ s/\.shop$//; # strip the trailing ".shop"
>     my $subr = $r->lookup_uri($uri);
>     $subr->run();
>         return Apache2::Const::OK ;
>   }
> 
> but both of those result in a loop : they end up requesting
> "/Shop_xxx/def/xyz.html", which hits the same Location, which runs the
> same handler, which then produces the frameset, and so on.

Here is how the cycle goes:

1) The server gets a request for /Shop_xxx/def/xyz.html, skips the
if-branch and generates the frameset.

2) The bottom frame generates another request for
/Shop_xxx/def/xyz.html.shop. It enters the if-branch and issues a
subrequest or an internal redirect for /Shop_xxx/def/xyz.html.

3) The subeq/redir enters the handler again. Now it avoids the if-branch
because it does not match /\.shop$/. So it spits out the frameset.

4) goto 2) by means of the browser

How to break the loop? Instead (or inside) of the LocationMatch above use:

PerlFixupHandler "sub {                                         \
  use Apache2::RequestUtil ();                                  \
  use Apache2::RequestRec ();                                   \
  use Apache2::Const -compile=>qw/DECLINE/;                     \
  my ($r)=@_;                                                   \
  if( $r->is_initial_req ) {                                    \
    $r->handler('modperl');                                     \
    $r->set_handlers(PerlResponseHandler=>'My::ShopResponse');  \
  }                                                             \
  return Apache2::Const::DECLINED;                              \
}"

Then step 3) reads:

3) The subreq/redir enters the request cycle again. The if-branch of
fixup handler is skipped because the request is not initial. Hence, the
PerlResponseHandler is skipped completely and the default handler sends
the document.

You can achieve a similar effect with mod_rewrite. It has IS_SUBREQ
available in RewriteCond. But I don't know if that also checks for
!$r->prev.

You can also try to modify your Response handler to decline if
!$r->is_initial_req:

  my $uri = $r->uri();
  if ($uri =~ s!(/[^/]+\.html?)\.shop$!$1!i) {
    $r->internal_redirect($uri);
    return Apache2::Const::OK ;
  }
  return Apache2::Const::DECLINE unless $r->is_initial_req;

I am not sure if that works. I think I have never tried to return
DECLINED from a response handler.

> So how do I tell Apache/mod_perl that this time "I mean it", and that it
> should directly deliver the requested file, without re-running the whole
> cycle ?
> 
> I can of course request the corresponding filename() and deliver it
> myself (perhaps with sendfile()), but that does not seem to be the most
> elegant way of doing this. Or is it ?
> 
> Oh, and I'd like it elegant, but I would prefer not having to introduce
> a PerlFixupHandler or a PerlOutputFilter or Javascript, and do it all
> within this ResponseHandler.  That's because I have colleagues who know
> even less about mod_perl than I do, and I'd like to leave them something
> simple to deal with in support and maintenance for another 10 years.
> 
> ...
> 
> Aside : I just tried
> 
>   my $uri = $r->uri();
>   if ($uri =~ m!\/([^/]+\.htm[l]?\.shop)$!i) {
>     $uri =~ s/\.shop$//; # strip the trailing ".shop"
>     my $subr = $r->lookup_uri($uri);
>     $r->sendfile($subr->filename());
>         return Apache2::Const::OK ;
>   }
> 
> and that works.  So I guess that /is/ the right solution here.

No, it's not.

The default handler does a bit more than just send $r->filename. For you
it may work but it won't in the general case. See default_handler() in
server/core.c.

Torsten


Re: question on sub-requests

Posted by André Warnier <aw...@ice-sa.com>.
Torsten Förtsch wrote:
> On 11/12/2012 06:19 PM, André Warnier wrote:
>> In response to some request URLs, I have to compose a response
>> structured as follows :
>>
>> - a html frameset document with two frames
>> - in the 1st frame, the result of another HTTP request to the same
>> Apache server.
>>   This URI of this HTTP request is created by "mangling" the original
>> request URL somewhat.
>> - in the 2d frame, the content of the HTML file corresponding to the
>> original request URI.
>>
>> For example, if the original request URI was something like :
>> "/abc/def/ghi.html", then
>>   - the top frame should contain the (html) output of a request to
>> "/cgi-bin/mangle.pl?arg=ghi"
>>   - the bottom frame should contain the content of the
>> originally-requested "/abc/def/ghi.html" URI (which is a static file).
>>
>> I am thinking of doing this by :
>> - creating a mod_perl ResponseHandler
>> - having this response handler make a first sub-request to the
>> "/cgi-bin/mangle.pl?arg=ghi" URI, grabbing the content of the response
>> to that sub-request, and insert it into the first <frame> of the output
>> <frameset> document.
>> - having the response handler do a lookup_uri of the original URI, get
>> the resulting filename, reading the file and insert its content into the
>> second <frame> of the output <frameset> document.
>>
>> My 1st question is : is the above a valid plan, or is there something
>> fundamentally wrong with this approach ?
>>
>> My 2d question is : looking at the Apache2::SubRequest documentation, I
>> do not see a clear way of getting the response content of a subrequest. 
>> For example, the run() method explanation seems to indicate that the
>> response content is sent directly to the client.
>> Am I missing something ?
> 
> I don't really understand what you want to achieve. But if you just want
> to insert a header on top of each page, this can be done without a
> frameset (you know, they are utterly deprecated).
> 
> Use a PerlOutputFilterHandler to insert a <div> or perhaps even an
> <iframe> just after the opening <body> tag.
> 
> Once you have found the <body> tag in the output stream, you pass it
> further down the filter chain and add perhaps the opening <div>. Then
> you create and run the subrequest. Then you put out the rest of the
> brigade, remove the filter and return. Thus, the filter will probably be
> called only once because the <body> tag tends to appear within the first
> few kbytes of the document.
> 
> If that is the case, you can even adjust the Content-Length header
> properly to include the additional stuff. Otherwise you should remove
> the Content-Length header.
> 
> Things you have to consider:
> 
> - filtering data costs CPU cylces
> This is especially true if you served just plain files before by
> sendfile(2).
> 
> - on the other hand, you can put mod_cache in front of those requests
> (even in the same apache) and they will be served even faster than the
> plain files before
> 
> - deleting the Content-Length header is to be avoided if possible. It
> increases the overall transfer time considerably
> 
> - if you have used precompressed plain files before they are now
> useless. Instead you'll have to use the DEFLATE filter. This costs
> additional CPU cycles. But again mod_cache helps a lot.
> 
> 
> One other idea comes to mind. If you want to stick with your frameset
> but prevent multiple requests perhaps you can use "data:" URLs as src.
> This probably requires much more complicated filtering.
> 
> Torsten
> 

Hi.
I didn't want to take too much time of anyone before, which is why I somewhat 
oversimplified the issue.  But considering the traffic on the lis os low, maybe you want 
to hear the whole story after all.

The basic case is this : a bit aside from our usual professional activities and for a 
friend, we run a website which is basically a shop with hundreds of individual items which 
people can view and buy.  (I will provide the URL privately to anyone who is more 
interested. It's a cute shop.)

The pages corresponding to these individual items, at the moment, are individual static 
pages in multiple sub-directories, and there are quite a lot of them.  The friend creates 
and maintains these static pages herself; she is an artist rather than a programmer, so 
she can handle an html editor (which she does rather well) to edit static pages and test 
them on her PC before copying them to the server, but we cannot ask her to handle any kind 
of "template" pages or the like.
Add to this that the basic logic of the website and the design and techniques used date 
back from some 10 years ago, have been patched and repatched several times over several 
years, and are rather bad.

Now there is a requirement that, instead of being just static pages, each of these pages 
should in addition contain a <form> with some specific item-related information, allowing 
to buy these items on-line (so it cannot be done just with an include or a stylesheet).

What I am trying to achieve, without having to edit each of these individual hundreds of 
pages, or changing the links to these pages, or change the basic design of the application 
(because there is no budget for that), is to find a clever way on the server side
to respond to a normal "/Shop_xxx/def/xyz.html" URL of one of these pages, to combine into 
one response both the required <form>, and the content of the existing unmodified static 
page.  I also do not want to parse the html on-the-fly and insert a <form> right into it, 
because the html that she creates with her (T-online) editor is rather bad to start with, 
and I have no guarantee that the result would be pleasing.

So that was the reason to think of the <frameset> solution, whereby in response to the 
initial request for "/Shop_xxx/def/xyz.html", I would respond with a first <frame> 
containing the form (generated by a back-end application, and depending on the item), and 
a second <frame> containing her artfully-crafted static page describing that item in all 
its glory.

The static pages in question are in several subdirectories of DocumentRoot, and at 
different levels.  Fortunately, all the top sub-directories names start with "/Shop_" 
(after which there can be "Quilts" or "Babydecken" and things like that, and a variable 
hierarchy of sub-directories containing html files and jpg images and the like.

So I have this configured :
<LocationMatch "^/Shop_">
   sethandler modperl
   PerlResponseHandler My::ShopResponse
   ...
</LocationMatch>

As a result in part of the previous communications on this list, this PerlResponseHandler
does more or less what I want, except one remaining problem which I am trying to resolve 
right now :
In response to an initial request for "/Shop_xxx/def/xyz.html", the handler generates a
<frameset> document as such :
<html>
<frameset rows="100,*">
   <frame name="top_frame" src="..the URI which generates the form.." />  (1)
   <frame name="bottom_frame" src="/Shop_xxx/def/xyz.html.shop" />  (2)
</frameset>
</html>

(1) for the dynamically-generated html <form> document
(2) for the static existing page

Because the second frame's URI also starts with "/Shop_", when the browser requests this 
frame, the same ResponseHandler is called.
The handler examines the URL and sees that it ends in ".shop" (instead of ".html").
So it knows that this time, it should not send another frameset, but instead it should 
strip the trailing ".shop" and deliver, as is, the content of the static document 
"/Shop_xxx/def/xyz.html".

But, how do I tell it to do that ?
I have tried :
   my $uri = $r->uri();
   if ($uri =~ m!\/([^/]+\.htm[l]?\.shop)$!i) {
	$uri =~ s/\.shop$//; # strip the trailing ".shop"
	$r->internal_redirect($uri);
     	return Apache2::Const::OK ;
   }

and also :

   my $uri = $r->uri();
   if ($uri =~ m!\/([^/]+\.htm[l]?\.shop)$!i) {
	$uri =~ s/\.shop$//; # strip the trailing ".shop"
	my $subr = $r->lookup_uri($uri);
	$subr->run();
     	return Apache2::Const::OK ;
   }

but both of those result in a loop : they end up requesting "/Shop_xxx/def/xyz.html", 
which hits the same Location, which runs the same handler, which then produces the 
frameset, and so on.

So how do I tell Apache/mod_perl that this time "I mean it", and that it should directly 
deliver the requested file, without re-running the whole cycle ?

I can of course request the corresponding filename() and deliver it myself (perhaps with 
sendfile()), but that does not seem to be the most elegant way of doing this. Or is it ?

Oh, and I'd like it elegant, but I would prefer not having to introduce a PerlFixupHandler 
or a PerlOutputFilter or Javascript, and do it all within this ResponseHandler.  That's 
because I have colleagues who know even less about mod_perl than I do, and I'd like to 
leave them something simple to deal with in support and maintenance for another 10 years.

...

Aside : I just tried

   my $uri = $r->uri();
   if ($uri =~ m!\/([^/]+\.htm[l]?\.shop)$!i) {
	$uri =~ s/\.shop$//; # strip the trailing ".shop"
	my $subr = $r->lookup_uri($uri);
	$r->sendfile($subr->filename());
     	return Apache2::Const::OK ;
   }

and that works.  So I guess that /is/ the right solution here.



Re: question on sub-requests

Posted by Torsten Förtsch <to...@gmx.net>.
On 11/12/2012 06:19 PM, André Warnier wrote:
> In response to some request URLs, I have to compose a response
> structured as follows :
> 
> - a html frameset document with two frames
> - in the 1st frame, the result of another HTTP request to the same
> Apache server.
>   This URI of this HTTP request is created by "mangling" the original
> request URL somewhat.
> - in the 2d frame, the content of the HTML file corresponding to the
> original request URI.
> 
> For example, if the original request URI was something like :
> "/abc/def/ghi.html", then
>   - the top frame should contain the (html) output of a request to
> "/cgi-bin/mangle.pl?arg=ghi"
>   - the bottom frame should contain the content of the
> originally-requested "/abc/def/ghi.html" URI (which is a static file).
> 
> I am thinking of doing this by :
> - creating a mod_perl ResponseHandler
> - having this response handler make a first sub-request to the
> "/cgi-bin/mangle.pl?arg=ghi" URI, grabbing the content of the response
> to that sub-request, and insert it into the first <frame> of the output
> <frameset> document.
> - having the response handler do a lookup_uri of the original URI, get
> the resulting filename, reading the file and insert its content into the
> second <frame> of the output <frameset> document.
> 
> My 1st question is : is the above a valid plan, or is there something
> fundamentally wrong with this approach ?
> 
> My 2d question is : looking at the Apache2::SubRequest documentation, I
> do not see a clear way of getting the response content of a subrequest. 
> For example, the run() method explanation seems to indicate that the
> response content is sent directly to the client.
> Am I missing something ?

I don't really understand what you want to achieve. But if you just want
to insert a header on top of each page, this can be done without a
frameset (you know, they are utterly deprecated).

Use a PerlOutputFilterHandler to insert a <div> or perhaps even an
<iframe> just after the opening <body> tag.

Once you have found the <body> tag in the output stream, you pass it
further down the filter chain and add perhaps the opening <div>. Then
you create and run the subrequest. Then you put out the rest of the
brigade, remove the filter and return. Thus, the filter will probably be
called only once because the <body> tag tends to appear within the first
few kbytes of the document.

If that is the case, you can even adjust the Content-Length header
properly to include the additional stuff. Otherwise you should remove
the Content-Length header.

Things you have to consider:

- filtering data costs CPU cylces
This is especially true if you served just plain files before by
sendfile(2).

- on the other hand, you can put mod_cache in front of those requests
(even in the same apache) and they will be served even faster than the
plain files before

- deleting the Content-Length header is to be avoided if possible. It
increases the overall transfer time considerably

- if you have used precompressed plain files before they are now
useless. Instead you'll have to use the DEFLATE filter. This costs
additional CPU cycles. But again mod_cache helps a lot.


One other idea comes to mind. If you want to stick with your frameset
but prevent multiple requests perhaps you can use "data:" URLs as src.
This probably requires much more complicated filtering.

Torsten

Re: question on sub-requests

Posted by gAzZaLi <ba...@bac2bac.com>.
Sure thing, anytime.

You raise valid points and are in the best position to know what kind of 
tradeoffs to make. Simpler handler requires less processing and memory 
but increased number of requests.

I said what I did because I'm working on a single page app. with heavy 
use of Javascript (Google's Closure) and happened to think of it.

If you're trying to serve valid HTML content in two frames as one valid
HTML page or output, then perhaps reexamining your problem will give you 
some other insight.


On 11/13/2012 1:04 AM, André Warnier wrote:
> Hi.
>
> Once again, thanks.  Your javascript/onLoad idea sounds good, and would
> fit my needs.
> I'll give it a spin.
>
> There is one thing that bothers me (and it is the same in my own
> solution outlined below) : what previously was one HTTP request and one
> response, now becomes 3 HTTP requests and 3 responses (one pair for the
> initial request; one pair each for each of the frames).
> It bothers me intellectually, because one of the points of this whole
> exercise was to make the whole process more efficient. I was hoping to
> be able to send back the whole frameset with the frames in it (and their
> content) in the initial response.  But that is not valid html.
> Oh well..
> On the other hand, this customer pays for bandwidth used. ;-)
>
>
>
>
> gAzZaLi wrote:
>>
>> Hi, you're welcome, glad to be of any help.
>> Sounds like you're close to getting it done or done
>> with it already.
>>
>> If you're interested, here's the redirect idea in a little
>> more detail and doesn't involve edits or renaming.
>>
>> All requests to html files in /abc/def/ could be handled with, say,
>>
>> RedirectMatch ^/abc/def/(.*)\.html$ /common/global.html?$1
>>
>> which loads the frameset file global.html (in the 'common' dir.) with
>> a param in the URL that denotes the actual file that was requested.
>>
>> Since the static file at /abc/def/ghi.html will be served up in the
>> bottom frame, and should not be intercepted by the RedirectMatch
>> above, /abc/def could use an alias, say
>>
>> Alias /bottomframecontent /var/www/htdocs/abc/def
>>
>> Here's global.html with a little Javascript to load the frames.
>>
>> global.html
>> -----------
>> <html><head>
>>
>> <script>
>> var loadFrames = function(){
>>      var viewFile = location.search.replace('?', '');
>>     document.getElementById('topframe').src =
>> "/perlResponseHandler?arg=" + viewFile;
>>      document.getElementById('bottomframe').src =
>> "/bottomframecontent/" + viewFile + ".html";
>> };
>>
>> window.onload = loadFrames;
>> </script>
>>
>> </head>
>>
>> <frameset rows="100, *">
>>     <frame name="topframe" src="">
>>     <frame id="bottomframe" src="">
>> </frameset>
>>
>> </html>
>> ------------
>>
>>
>>
>>
>> On 11/12/2012 3:42 PM, André Warnier wrote:
>>> Hi.
>>> Thank you for your response.
>>> You are not missing the point of my questions.
>>>
>>> But I do not really have control over the requests.  Or rather, I do,
>>> but there are hundreds of pages containing hundreds of similar (but not
>>> equal) links, and it is in the practice not doable to edit them all..
>>> And my "mangle.pl" URI was an oversimplification for the sake of this
>>> post.  The real URI for that first frame is more complicated to
>>> generate, and beyond what I can do with mod_rewrite et al.
>>>
>>> But second, I just realised that I cannot do things the way I explain
>>> below anyway, because inside a <frame> tag, you cannot put content. You
>>> can only use <frame src="..URI..">.
>>> So basically, my skeleton ResponseHandler works as I expected and does
>>> create the <frameset> document that I wanted and returns it, but that
>>> document is invalid html.
>>> Shucks. Back to the drawing board.
>>>
>>> Which now creates another issue :
>>> I could create instead a document like :
>>> <html>
>>> <head></head>
>>> <frameset rows="100,*">
>>>    <frame name="topframe" src="/cgi-bin/mangle.pl?arg=ghi" />
>>>    <frame name="bottomframe" src=/abc/def/ghi.html">
>>> </frameset>
>>> </html>
>>>
>>> but.. the URI of the request for the second frame would trigger my
>>> ResponseHandler again, and I'd be stuck in a forever-loop of embedded
>>> frames, fractal-like.
>>>
>>> So now I am going to re-read your suggestions below, and see if I can
>>> figure out something along those lines which does not force me to edit
>>> and/or rename all the pages.
>>>
>>> Maybe instead of generating the second frame as
>>>    <frame name="bottomframe" src=/abc/def/ghi.html">
>>> I can instead generate it as
>>>    <frame name="bottomframe" src=/abc/def/ghi.html.perl">
>>> and then detect this in the Handler, change the $r->uri back to the
>>> correct one, and let Apache's default handler serve it by returning
>>> DECLINED.  I'll try that.
>>>
>>> Thanks for helping me think.
>>>
>>>
>>> gAzZaLi wrote:
>>>>
>>>> Q1: At first glance, using a mod_perl handler to serve an existing
>>>> static html file seems like overkill.
>>>>
>>>> Couldn't Apache respond (RedirectMatch?) with a common frameset html
>>>> file with some Javascript, which then fills the first frame with the
>>>> response to mangle.pl and the second frame with the static html file?
>>>>
>>>> If you have control over the creation of the request URLs, you could
>>>> also have them come in as say, "show.html?ghi", which will be a
>>>> frameset html file which works as above and not have Apache do any
>>>> extra work.
>>>>
>>>> In each case, your mod_perl handler would be simpler and deal only
>>>> with responding to the value of arg.
>>>>
>>>> Of course you may have already considered and rejected these ideas and
>>>> I'm missing the point entirely.
>>>>
>>>>
>>>> On 11/12/2012 9:19 AM, André Warnier wrote:
>>>>> Hi.
>>>>>
>>>>> context: Apache2.x, mod_perl 2.x
>>>>>
>>>>> In response to some request URLs, I have to compose a response
>>>>> structured as follows :
>>>>>
>>>>> - a html frameset document with two frames
>>>>> - in the 1st frame, the result of another HTTP request to the same
>>>>> Apache server.
>>>>>    This URI of this HTTP request is created by "mangling" the original
>>>>> request URL somewhat.
>>>>> - in the 2d frame, the content of the HTML file corresponding to the
>>>>> original request URI.
>>>>>
>>>>> For example, if the original request URI was something like :
>>>>> "/abc/def/ghi.html", then
>>>>>    - the top frame should contain the (html) output of a request to
>>>>> "/cgi-bin/mangle.pl?arg=ghi"
>>>>>    - the bottom frame should contain the content of the
>>>>> originally-requested "/abc/def/ghi.html" URI (which is a static file).
>>>>>
>>>>> I am thinking of doing this by :
>>>>> - creating a mod_perl ResponseHandler
>>>>> - having this response handler make a first sub-request to the
>>>>> "/cgi-bin/mangle.pl?arg=ghi" URI, grabbing the content of the response
>>>>> to that sub-request, and insert it into the first <frame> of the
>>>>> output
>>>>> <frameset> document.
>>>>> - having the response handler do a lookup_uri of the original URI, get
>>>>> the resulting filename, reading the file and insert its content
>>>>> into the
>>>>> second <frame> of the output <frameset> document.
>>>>>
>>>>> My 1st question is : is the above a valid plan, or is there something
>>>>> fundamentally wrong with this approach ?
>>>>>
>>>>> My 2d question is : looking at the Apache2::SubRequest
>>>>> documentation, I
>>>>> do not see a clear way of getting the response content of a
>>>>> subrequest.
>>>>> For example, the run() method explanation seems to indicate that the
>>>>> response content is sent directly to the client.
>>>>> Am I missing something ?
>>>>>
>>>>> TIA
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>>
>>
>>
>
>
>


Re: question on sub-requests

Posted by André Warnier <aw...@ice-sa.com>.
Hi.

Once again, thanks.  Your javascript/onLoad idea sounds good, and would fit my needs.
I'll give it a spin.

There is one thing that bothers me (and it is the same in my own solution outlined below) 
: what previously was one HTTP request and one response, now becomes 3 HTTP requests and 3 
responses (one pair for the initial request; one pair each for each of the frames).
It bothers me intellectually, because one of the points of this whole exercise was to make 
the whole process more efficient. I was hoping to be able to send back the whole frameset 
with the frames in it (and their content) in the initial response.  But that is not valid 
html.
Oh well..
On the other hand, this customer pays for bandwidth used. ;-)




gAzZaLi wrote:
> 
> Hi, you're welcome, glad to be of any help.
> Sounds like you're close to getting it done or done
> with it already.
> 
> If you're interested, here's the redirect idea in a little
> more detail and doesn't involve edits or renaming.
> 
> All requests to html files in /abc/def/ could be handled with, say,
> 
> RedirectMatch ^/abc/def/(.*)\.html$ /common/global.html?$1
> 
> which loads the frameset file global.html (in the 'common' dir.) with a 
> param in the URL that denotes the actual file that was requested.
> 
> Since the static file at /abc/def/ghi.html will be served up in the 
> bottom frame, and should not be intercepted by the RedirectMatch above, 
> /abc/def could use an alias, say
> 
> Alias /bottomframecontent /var/www/htdocs/abc/def
> 
> Here's global.html with a little Javascript to load the frames.
> 
> global.html
> -----------
> <html><head>
> 
> <script>
> var loadFrames = function(){
>      var viewFile = location.search.replace('?', '');
>     
>     document.getElementById('topframe').src = 
> "/perlResponseHandler?arg=" + viewFile;   
> 
>      document.getElementById('bottomframe').src = "/bottomframecontent/" 
> + viewFile + ".html";
> };
> 
> window.onload = loadFrames;
> </script>
> 
> </head>
> 
> <frameset rows="100, *">
>     <frame name="topframe" src="">
>     <frame id="bottomframe" src="">
> </frameset>
> 
> </html>
> ------------
> 
> 
> 
> 
> On 11/12/2012 3:42 PM, André Warnier wrote:
>> Hi.
>> Thank you for your response.
>> You are not missing the point of my questions.
>>
>> But I do not really have control over the requests.  Or rather, I do,
>> but there are hundreds of pages containing hundreds of similar (but not
>> equal) links, and it is in the practice not doable to edit them all..
>> And my "mangle.pl" URI was an oversimplification for the sake of this
>> post.  The real URI for that first frame is more complicated to
>> generate, and beyond what I can do with mod_rewrite et al.
>>
>> But second, I just realised that I cannot do things the way I explain
>> below anyway, because inside a <frame> tag, you cannot put content. You
>> can only use <frame src="..URI..">.
>> So basically, my skeleton ResponseHandler works as I expected and does
>> create the <frameset> document that I wanted and returns it, but that
>> document is invalid html.
>> Shucks. Back to the drawing board.
>>
>> Which now creates another issue :
>> I could create instead a document like :
>> <html>
>> <head></head>
>> <frameset rows="100,*">
>>    <frame name="topframe" src="/cgi-bin/mangle.pl?arg=ghi" />
>>    <frame name="bottomframe" src=/abc/def/ghi.html">
>> </frameset>
>> </html>
>>
>> but.. the URI of the request for the second frame would trigger my
>> ResponseHandler again, and I'd be stuck in a forever-loop of embedded
>> frames, fractal-like.
>>
>> So now I am going to re-read your suggestions below, and see if I can
>> figure out something along those lines which does not force me to edit
>> and/or rename all the pages.
>>
>> Maybe instead of generating the second frame as
>>    <frame name="bottomframe" src=/abc/def/ghi.html">
>> I can instead generate it as
>>    <frame name="bottomframe" src=/abc/def/ghi.html.perl">
>> and then detect this in the Handler, change the $r->uri back to the
>> correct one, and let Apache's default handler serve it by returning
>> DECLINED.  I'll try that.
>>
>> Thanks for helping me think.
>>
>>
>> gAzZaLi wrote:
>>>
>>> Q1: At first glance, using a mod_perl handler to serve an existing
>>> static html file seems like overkill.
>>>
>>> Couldn't Apache respond (RedirectMatch?) with a common frameset html
>>> file with some Javascript, which then fills the first frame with the
>>> response to mangle.pl and the second frame with the static html file?
>>>
>>> If you have control over the creation of the request URLs, you could
>>> also have them come in as say, "show.html?ghi", which will be a
>>> frameset html file which works as above and not have Apache do any
>>> extra work.
>>>
>>> In each case, your mod_perl handler would be simpler and deal only
>>> with responding to the value of arg.
>>>
>>> Of course you may have already considered and rejected these ideas and
>>> I'm missing the point entirely.
>>>
>>>
>>> On 11/12/2012 9:19 AM, André Warnier wrote:
>>>> Hi.
>>>>
>>>> context: Apache2.x, mod_perl 2.x
>>>>
>>>> In response to some request URLs, I have to compose a response
>>>> structured as follows :
>>>>
>>>> - a html frameset document with two frames
>>>> - in the 1st frame, the result of another HTTP request to the same
>>>> Apache server.
>>>>    This URI of this HTTP request is created by "mangling" the original
>>>> request URL somewhat.
>>>> - in the 2d frame, the content of the HTML file corresponding to the
>>>> original request URI.
>>>>
>>>> For example, if the original request URI was something like :
>>>> "/abc/def/ghi.html", then
>>>>    - the top frame should contain the (html) output of a request to
>>>> "/cgi-bin/mangle.pl?arg=ghi"
>>>>    - the bottom frame should contain the content of the
>>>> originally-requested "/abc/def/ghi.html" URI (which is a static file).
>>>>
>>>> I am thinking of doing this by :
>>>> - creating a mod_perl ResponseHandler
>>>> - having this response handler make a first sub-request to the
>>>> "/cgi-bin/mangle.pl?arg=ghi" URI, grabbing the content of the response
>>>> to that sub-request, and insert it into the first <frame> of the output
>>>> <frameset> document.
>>>> - having the response handler do a lookup_uri of the original URI, get
>>>> the resulting filename, reading the file and insert its content into 
>>>> the
>>>> second <frame> of the output <frameset> document.
>>>>
>>>> My 1st question is : is the above a valid plan, or is there something
>>>> fundamentally wrong with this approach ?
>>>>
>>>> My 2d question is : looking at the Apache2::SubRequest documentation, I
>>>> do not see a clear way of getting the response content of a subrequest.
>>>> For example, the run() method explanation seems to indicate that the
>>>> response content is sent directly to the client.
>>>> Am I missing something ?
>>>>
>>>> TIA
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
> 
> 


Re: question on sub-requests

Posted by gAzZaLi <ba...@bac2bac.com>.
Hi, you're welcome, glad to be of any help.
Sounds like you're close to getting it done or done
with it already.

If you're interested, here's the redirect idea in a little
more detail and doesn't involve edits or renaming.

All requests to html files in /abc/def/ could be handled with, say,

RedirectMatch ^/abc/def/(.*)\.html$ /common/global.html?$1

which loads the frameset file global.html (in the 'common' dir.) with a 
param in the URL that denotes the actual file that was requested.

Since the static file at /abc/def/ghi.html will be served up in the 
bottom frame, and should not be intercepted by the RedirectMatch above, 
/abc/def could use an alias, say

Alias /bottomframecontent /var/www/htdocs/abc/def

Here's global.html with a little Javascript to load the frames.

global.html
-----------
<html><head>

<script>
var loadFrames = function(){
      var viewFile = location.search.replace('?', '');
	
     document.getElementById('topframe').src = 
"/perlResponseHandler?arg=" + viewFile;	

      document.getElementById('bottomframe').src = 
"/bottomframecontent/" + viewFile + ".html";
};

window.onload = loadFrames;
</script>

</head>

<frameset rows="100, *">
     <frame name="topframe" src="">
     <frame id="bottomframe" src="">
</frameset>

</html>
------------




On 11/12/2012 3:42 PM, André Warnier wrote:
> Hi.
> Thank you for your response.
> You are not missing the point of my questions.
>
> But I do not really have control over the requests.  Or rather, I do,
> but there are hundreds of pages containing hundreds of similar (but not
> equal) links, and it is in the practice not doable to edit them all..
> And my "mangle.pl" URI was an oversimplification for the sake of this
> post.  The real URI for that first frame is more complicated to
> generate, and beyond what I can do with mod_rewrite et al.
>
> But second, I just realised that I cannot do things the way I explain
> below anyway, because inside a <frame> tag, you cannot put content. You
> can only use <frame src="..URI..">.
> So basically, my skeleton ResponseHandler works as I expected and does
> create the <frameset> document that I wanted and returns it, but that
> document is invalid html.
> Shucks. Back to the drawing board.
>
> Which now creates another issue :
> I could create instead a document like :
> <html>
> <head></head>
> <frameset rows="100,*">
>    <frame name="topframe" src="/cgi-bin/mangle.pl?arg=ghi" />
>    <frame name="bottomframe" src=/abc/def/ghi.html">
> </frameset>
> </html>
>
> but.. the URI of the request for the second frame would trigger my
> ResponseHandler again, and I'd be stuck in a forever-loop of embedded
> frames, fractal-like.
>
> So now I am going to re-read your suggestions below, and see if I can
> figure out something along those lines which does not force me to edit
> and/or rename all the pages.
>
> Maybe instead of generating the second frame as
>    <frame name="bottomframe" src=/abc/def/ghi.html">
> I can instead generate it as
>    <frame name="bottomframe" src=/abc/def/ghi.html.perl">
> and then detect this in the Handler, change the $r->uri back to the
> correct one, and let Apache's default handler serve it by returning
> DECLINED.  I'll try that.
>
> Thanks for helping me think.
>
>
> gAzZaLi wrote:
>>
>> Q1: At first glance, using a mod_perl handler to serve an existing
>> static html file seems like overkill.
>>
>> Couldn't Apache respond (RedirectMatch?) with a common frameset html
>> file with some Javascript, which then fills the first frame with the
>> response to mangle.pl and the second frame with the static html file?
>>
>> If you have control over the creation of the request URLs, you could
>> also have them come in as say, "show.html?ghi", which will be a
>> frameset html file which works as above and not have Apache do any
>> extra work.
>>
>> In each case, your mod_perl handler would be simpler and deal only
>> with responding to the value of arg.
>>
>> Of course you may have already considered and rejected these ideas and
>> I'm missing the point entirely.
>>
>>
>> On 11/12/2012 9:19 AM, André Warnier wrote:
>>> Hi.
>>>
>>> context: Apache2.x, mod_perl 2.x
>>>
>>> In response to some request URLs, I have to compose a response
>>> structured as follows :
>>>
>>> - a html frameset document with two frames
>>> - in the 1st frame, the result of another HTTP request to the same
>>> Apache server.
>>>    This URI of this HTTP request is created by "mangling" the original
>>> request URL somewhat.
>>> - in the 2d frame, the content of the HTML file corresponding to the
>>> original request URI.
>>>
>>> For example, if the original request URI was something like :
>>> "/abc/def/ghi.html", then
>>>    - the top frame should contain the (html) output of a request to
>>> "/cgi-bin/mangle.pl?arg=ghi"
>>>    - the bottom frame should contain the content of the
>>> originally-requested "/abc/def/ghi.html" URI (which is a static file).
>>>
>>> I am thinking of doing this by :
>>> - creating a mod_perl ResponseHandler
>>> - having this response handler make a first sub-request to the
>>> "/cgi-bin/mangle.pl?arg=ghi" URI, grabbing the content of the response
>>> to that sub-request, and insert it into the first <frame> of the output
>>> <frameset> document.
>>> - having the response handler do a lookup_uri of the original URI, get
>>> the resulting filename, reading the file and insert its content into the
>>> second <frame> of the output <frameset> document.
>>>
>>> My 1st question is : is the above a valid plan, or is there something
>>> fundamentally wrong with this approach ?
>>>
>>> My 2d question is : looking at the Apache2::SubRequest documentation, I
>>> do not see a clear way of getting the response content of a subrequest.
>>> For example, the run() method explanation seems to indicate that the
>>> response content is sent directly to the client.
>>> Am I missing something ?
>>>
>>> TIA
>>>
>>>
>>>
>>
>>
>
>
>


Re: question on sub-requests

Posted by André Warnier <aw...@ice-sa.com>.
Hi.
Thank you for your response.
You are not missing the point of my questions.

But I do not really have control over the requests.  Or rather, I do, but there are 
hundreds of pages containing hundreds of similar (but not equal) links, and it is in the 
practice not doable to edit them all..
And my "mangle.pl" URI was an oversimplification for the sake of this post.  The real URI 
for that first frame is more complicated to generate, and beyond what I can do with 
mod_rewrite et al.

But second, I just realised that I cannot do things the way I explain below anyway, 
because inside a <frame> tag, you cannot put content. You can only use <frame src="..URI..">.
So basically, my skeleton ResponseHandler works as I expected and does create the 
<frameset> document that I wanted and returns it, but that document is invalid html.
Shucks. Back to the drawing board.

Which now creates another issue :
I could create instead a document like :
<html>
<head></head>
<frameset rows="100,*">
   <frame name="topframe" src="/cgi-bin/mangle.pl?arg=ghi" />
   <frame name="bottomframe" src=/abc/def/ghi.html">
</frameset>
</html>

but.. the URI of the request for the second frame would trigger my ResponseHandler again, 
and I'd be stuck in a forever-loop of embedded frames, fractal-like.

So now I am going to re-read your suggestions below, and see if I can figure out something 
along those lines which does not force me to edit and/or rename all the pages.

Maybe instead of generating the second frame as
   <frame name="bottomframe" src=/abc/def/ghi.html">
I can instead generate it as
   <frame name="bottomframe" src=/abc/def/ghi.html.perl">
and then detect this in the Handler, change the $r->uri back to the correct one, and let 
Apache's default handler serve it by returning DECLINED.  I'll try that.

Thanks for helping me think.


gAzZaLi wrote:
> 
> Q1: At first glance, using a mod_perl handler to serve an existing 
> static html file seems like overkill.
> 
> Couldn't Apache respond (RedirectMatch?) with a common frameset html 
> file with some Javascript, which then fills the first frame with the 
> response to mangle.pl and the second frame with the static html file?
> 
> If you have control over the creation of the request URLs, you could 
> also have them come in as say, "show.html?ghi", which will be a frameset 
> html file which works as above and not have Apache do any extra work.
> 
> In each case, your mod_perl handler would be simpler and deal only with 
> responding to the value of arg.
> 
> Of course you may have already considered and rejected these ideas and 
> I'm missing the point entirely.
> 
> 
> On 11/12/2012 9:19 AM, André Warnier wrote:
>> Hi.
>>
>> context: Apache2.x, mod_perl 2.x
>>
>> In response to some request URLs, I have to compose a response
>> structured as follows :
>>
>> - a html frameset document with two frames
>> - in the 1st frame, the result of another HTTP request to the same
>> Apache server.
>>    This URI of this HTTP request is created by "mangling" the original
>> request URL somewhat.
>> - in the 2d frame, the content of the HTML file corresponding to the
>> original request URI.
>>
>> For example, if the original request URI was something like :
>> "/abc/def/ghi.html", then
>>    - the top frame should contain the (html) output of a request to
>> "/cgi-bin/mangle.pl?arg=ghi"
>>    - the bottom frame should contain the content of the
>> originally-requested "/abc/def/ghi.html" URI (which is a static file).
>>
>> I am thinking of doing this by :
>> - creating a mod_perl ResponseHandler
>> - having this response handler make a first sub-request to the
>> "/cgi-bin/mangle.pl?arg=ghi" URI, grabbing the content of the response
>> to that sub-request, and insert it into the first <frame> of the output
>> <frameset> document.
>> - having the response handler do a lookup_uri of the original URI, get
>> the resulting filename, reading the file and insert its content into the
>> second <frame> of the output <frameset> document.
>>
>> My 1st question is : is the above a valid plan, or is there something
>> fundamentally wrong with this approach ?
>>
>> My 2d question is : looking at the Apache2::SubRequest documentation, I
>> do not see a clear way of getting the response content of a subrequest.
>> For example, the run() method explanation seems to indicate that the
>> response content is sent directly to the client.
>> Am I missing something ?
>>
>> TIA
>>
>>
>>
> 
> 


Re: question on sub-requests

Posted by gAzZaLi <ba...@bac2bac.com>.
Q1: At first glance, using a mod_perl handler to serve an existing 
static html file seems like overkill.

Couldn't Apache respond (RedirectMatch?) with a common frameset html 
file with some Javascript, which then fills the first frame with the 
response to mangle.pl and the second frame with the static html file?

If you have control over the creation of the request URLs, you could 
also have them come in as say, "show.html?ghi", which will be a frameset 
html file which works as above and not have Apache do any extra work.

In each case, your mod_perl handler would be simpler and deal only with 
responding to the value of arg.

Of course you may have already considered and rejected these ideas and 
I'm missing the point entirely.


On 11/12/2012 9:19 AM, André Warnier wrote:
> Hi.
>
> context: Apache2.x, mod_perl 2.x
>
> In response to some request URLs, I have to compose a response
> structured as follows :
>
> - a html frameset document with two frames
> - in the 1st frame, the result of another HTTP request to the same
> Apache server.
>    This URI of this HTTP request is created by "mangling" the original
> request URL somewhat.
> - in the 2d frame, the content of the HTML file corresponding to the
> original request URI.
>
> For example, if the original request URI was something like :
> "/abc/def/ghi.html", then
>    - the top frame should contain the (html) output of a request to
> "/cgi-bin/mangle.pl?arg=ghi"
>    - the bottom frame should contain the content of the
> originally-requested "/abc/def/ghi.html" URI (which is a static file).
>
> I am thinking of doing this by :
> - creating a mod_perl ResponseHandler
> - having this response handler make a first sub-request to the
> "/cgi-bin/mangle.pl?arg=ghi" URI, grabbing the content of the response
> to that sub-request, and insert it into the first <frame> of the output
> <frameset> document.
> - having the response handler do a lookup_uri of the original URI, get
> the resulting filename, reading the file and insert its content into the
> second <frame> of the output <frameset> document.
>
> My 1st question is : is the above a valid plan, or is there something
> fundamentally wrong with this approach ?
>
> My 2d question is : looking at the Apache2::SubRequest documentation, I
> do not see a clear way of getting the response content of a subrequest.
> For example, the run() method explanation seems to indicate that the
> response content is sent directly to the client.
> Am I missing something ?
>
> TIA
>
>
>