Re: Subrequests
Miroslav Madzarevic wrote: > Is it possible that my perl script (Apache::Registry, > Apache::PerlRun, HTML::Mason or whatever) could run multiple > times with same parameters when the user just invokes the URL > once (for example clicks on tag) and if so how can I prevent > this from happening. if(!$r->is_main()) { return; } -- Pierre Phaneuf
Re: Subrequests
Hi there, On Thu, 7 Feb 2002, Miroslav Madzarevic wrote: > Is it possible that my perl script (Apache::Registry, Apache::PerlRun, > HTML::Mason or whatever) could run multiple times with same parameters when the > user just invokes the URL once (for example clicks on tag) and if so how > can I prevent this from happening. > > I guess this is because of subrequests being fired and I _explicitly_ don't > wish my code to run multiple times because strange things might happen. There are lots of ways of finding out what happens when a request comes in. Read the debugging section of the mod_perl Guide: http://perl.apache.org/guide. I favour tailing the error_log and printing truckloads of debug info in there as a matter of routine. (Amazing what you find, sometimes. :) Browsers like Netscape can fire off lots of parallel requests. You might not expect them to do that. Even if everything works like you expect, if it runs on a Webserver how are you going to prevent people double-clicking, or lots of people all clicking at once? You'd better fix your code so it can cope. 73, Ged.
Subrequests
Is it possible that my perl script (Apache::Registry, Apache::PerlRun, HTML::Mason or whatever) could run multiple times with same parameters when the user just invokes the URL once (for example clicks on tag) and if so how can I prevent this from happening. I guess this is because of subrequests being fired and I _explicitly_ don't wish my code to run multiple times because strange things might happen.
Re: Passing data to subrequests
Hi there, On Fri, 6 Apr 2001, Joachim Zobel wrote: > Is content negotiation somehow uncool? I could not find an > Apache::Negotiate to interface with mod_negotiate and its remarkably > little discussed. Probably because whatever the results of the negotiation, Internet Exploder will probably ignore them. :( 73, Ged.
Passing data to subrequests
Hi. I still think about a way to use content negotiated templates. My favourite solution is now to make my template filler a content handler for the template direktory. The problem is to pass the data the handler should fill in. How do I pass larger data structures to a subrequest? Is there a way to do a POST subrequest? How long can a notes entry be? Any hints? Thanx, Joachim Is content negotiation somehow uncool? I could not find an Apache::Negotiate to interface with mod_negotiate and its remarkably little discussed. -- "... ein Geschlecht erfinderischer Zwerge, die fuer alles gemietet werden koennen."- Bertolt Brecht - Leben des Galilei
RE: $r->pnotes and SubRequests
> -Original Message- > From: Nikolaus Rath [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, March 07, 2001 12:18 PM > To: [EMAIL PROTECTED] > Subject: $r->pnotes and SubRequests > > > Hello! > > When i define a pnote for a request, can i access this pnote in a > handler handling a sub request of the first request? $r->prev->pnotes() HTH --Geoff > > - Nikolaus > > -- > Heute kann man ja kaum noch eine AOL-CD aus dem Fenster werfen, ohne > jemanden zu treffen, der einen SuSE-Karton unter dem Arm trägt. >- Jochem Huhmann, > de.comp.os.unix.discussion >
$r->pnotes and SubRequests
Hello! When i define a pnote for a request, can i access this pnote in a handler handling a sub request of the first request? - Nikolaus -- Heute kann man ja kaum noch eine AOL-CD aus dem Fenster werfen, ohne jemanden zu treffen, der einen SuSE-Karton unter dem Arm trägt. - Jochem Huhmann, de.comp.os.unix.discussion
Re: A really really weird use for subrequests...
On Wed, 4 Oct 2000, Jim Winstead wrote: >On Oct 04, Luis 'Champs' de Carvalho wrote: >> Can i make the mod_proxy redirect using a sub-request, and still >> have the contents (and headers, and everything else) to let apache handle >> the response phase ? >no. That's great. there is any possible workarround? >> If not, how can i do this weird thing? >take a look at Apache::RewritingProxy. >http://search.cpan.org/search?dist=Apache-RewritingProxy Thank you for the link, Jim. This was the base for my project. Take a look at http://www.sourceforge.net/projects/myproxy/ I need something a litte better... mod_proxy will help great... Lack of ideas... Any suggestions? thank you all again. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Luis 'Champs' de Carvalho @@ @@ @@ SysAdmin at TBN @@ @@ @@ mail to:[EMAIL PROTECTED] @@ @@ http://www.tbn.com.br/@@ @@ Phone: +55(011)3842.9967@@ @@ "There's no spoon." @@ @@ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Re: A really really weird use for subrequests...
On Oct 04, Luis 'Champs' de Carvalho wrote: > Can i make the mod_proxy redirect using a sub-request, and still > have the contents (and headers, and everything else) to let apache handle > the response phase ? no. > If not, how can i do this weird thing? take a look at Apache::RewritingProxy. http://search.cpan.org/search?dist=Apache-RewritingProxy jim
A really really weird use for subrequests...
Hy, list people. I'm need build a rewriting proxy module for my apache. The basic idea is get a request, turn it on a proxy request as described in the eagle book @ page 371, rewrite the $request->contents so the client will come back to me when processing the next request and let apache follow the content generation process and response phase as it allways do. I know how to make the transformation to a mod_proxy request. I also know that the mod_proxy will bring me the right page, so i simply don't care about this stage. But i *really* *don't* *know* how to rewrite the response *before* the mod_proxy sends it back to the client. Can i make the mod_proxy redirect using a sub-request, and still have the contents (and headers, and everything else) to let apache handle the response phase ? If not, how can i do this weird thing? thank you all in advance for any ideas! []'z! =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Luis 'Champs' de Carvalho @@ @@ @@ SysAdmin at TBN @@ @@ @@ mail to:[EMAIL PROTECTED] @@ @@ http://www.tbn.com.br/@@ @@ Phone: +55(011)3842.9967@@ @@ "There's no spoon." @@ @@ =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Re: STDIN and subrequests
thanx, Andrei That could work. However, am I not limited to a certain size GET string? Or are GET strings of unlimited size when issued internally by a SubRequest and not an actual client? One definite problem is that that cgi in question would need to know how to handle both GET and POST requests. Some legacy cgi on our servers may only know how to do one or the other. any other ideas? -amen "Andrei A. Voropaev" wrote: > I feel like it would be simpler to append content of STDIN to the > URL. In other words convert POST request to GET. > > Andrei > > On Wed, Aug 23, 2000 at 10:03:59PM -0700, Alex Menendez wrote: > > hello, all > > > > I am currently trying to have a cgi execute in a mod_perl module by > > generating a subrequest to the executable via > > lookup_uri. It is working great for GET requests. However, POST requests > > are obviously failing because only the uri is being passed to the > > subrequest and not the main request's STDIN. I assume the answer is to > > tie the main request's STDIN to the subrequest's STDIN. I have tried to > > to this with tie but I get an error because the subclass > > Apache::SubRequest cannot execute a tie. > > > > Any ideas? > > > > -amen > > --
STDIN and subrequests
hello, all I am currently trying to have a cgi execute in a mod_perl module by generating a subrequest to the executable via lookup_uri. It is working great for GET requests. However, POST requests are obviously failing because only the uri is being passed to the subrequest and not the main request's STDIN. I assume the answer is to tie the main request's STDIN to the subrequest's STDIN. I have tried to to this with tie but I get an error because the subclass Apache::SubRequest cannot execute a tie. Any ideas? -amen
Re: cgis and subrequests
hey, guys just for the recordI finally got this thing to work. However, it does have some bizarre behavior. After compiling the patch, $subr->run(1) returns headers without calling the send_http_header method. This holds true for static files and for cgis that only set the content type header. For cgis that add any additional header like Location, the headers are not returned unless you explicitly call send_http_header. I know that our cgi's at most only alter the Location header in addition to content type...so...I coded around this with the following: my $subr = $r->lookup_uri($uri); if($r->dir_config('is_cgi')) { $subr->handler('cgi-script'); } else { $subr->handler('server-parsed'); } $subr->run(1); if($subr->header_out('Location')) { $subr->send_http_header; } else { $r->print(&create_img_tag($file,$SCRIPT_ON,$status)); } my $status = $subr->status; return $status; if I always called send_http_header, a second set of HTTP headers would be appended to static documents and to cgis that only change the content type header. Just an FYI... -amen Doug MacEachern wrote: > On Mon, 21 Aug 2000, Alex Menendez wrote: > > > > > ok, what about cgi's that generate Location: headers. Am I out of luck > > here? should I contemplate changing src for ap_run_sub_req > > doh, right, headers are not added until run(). no need to change > ap_run_sub_req, we can support this. with the patch below you can say > $subr->run(1), where 1 enables send_http_header() within subrequests. > > --- src/modules/perl/Apache.xs 2000/08/15 19:36:32 1.103 > +++ src/modules/perl/Apache.xs 2000/08/21 19:38:32 > @@ -1996,10 +2003,15 @@ > "Apache::SubRequest::DESTROY(0x%lx)\n", (unsigned long)r)); > > int > -run(r) > +run(r, allow_send_header=0) > Apache::SubRequest r > +int allow_send_header > > CODE: > +if (allow_send_header) { > +r->assbackwards = 0; > +} > + > RETVAL = run_sub_req(r); > > OUTPUT:
Re: cgis and subrequests
On Mon, 21 Aug 2000, Alex Menendez wrote: > > ok, what about cgi's that generate Location: headers. Am I out of luck > here? should I contemplate changing src for ap_run_sub_req doh, right, headers are not added until run(). no need to change ap_run_sub_req, we can support this. with the patch below you can say $subr->run(1), where 1 enables send_http_header() within subrequests. --- src/modules/perl/Apache.xs 2000/08/15 19:36:32 1.103 +++ src/modules/perl/Apache.xs 2000/08/21 19:38:32 @@ -1996,10 +2003,15 @@ "Apache::SubRequest::DESTROY(0x%lx)\n", (unsigned long)r)); int -run(r) +run(r, allow_send_header=0) Apache::SubRequest r +int allow_send_header CODE: +if (allow_send_header) { +r->assbackwards = 0; +} + RETVAL = run_sub_req(r); OUTPUT:
Re: cgis and subrequests
ok, what about cgi's that generate Location: headers. Am I out of luck here? should I contemplate changing src for ap_run_sub_req thanx, -amen On Mon, 21 Aug 2000, Doug MacEachern wrote: > whoops. yeah, $subr->send_http_header won't work for the same reason > send_http_header() calls within run() do not. you'll just need to > propagate subrequest info like so: > > my $subr = $r->lookup_uri($uri); > > $r->send_http_header($subr->content_type); > > $subr->run; > >
Re: cgis and subrequests
whoops. yeah, $subr->send_http_header won't work for the same reason send_http_header() calls within run() do not. you'll just need to propagate subrequest info like so: my $subr = $r->lookup_uri($uri); $r->send_http_header($subr->content_type); $subr->run;
Re: cgis and subrequests
h, I have tried what you suggested and it is still not generating the headers. I have tried calling the send_http_header function both before and after the handler switch and it still is not working. I think it is bug but I am not sure. At any rate, here is some of the module code and the http.conf directives: my $uri = $r->uri; unless(!$r->args) { $uri = $uri .'?'.$r->args; } my $subr = $r->lookup_uri($uri); if($r->dir_config('is_cgi')) { $subr->handler('cgi-script'); } else { $subr->handler('server-parsed'); } $subr->send_http_header; $subr->run(); my $status = $subr->status; $subr->print(&create_img_tag($file,$SCRIPT_ON,$status)); return $status; SetHandler perl-script PerlHandler Macromedia::AddStatImage SetHandler perl-script PerlHandler Macromedia::AddStatImage PerlSetVar is_cgi 1 any ideas? -amen On Mon, 21 Aug 2000, Doug MacEachern wrote: > On Sun, 20 Aug 2000, Alex Menendez wrote: > > > unfortunately, I am not entirely sure what a cgi is going to output all the > > time. The cgi might try to do a redirect using the Location field. Therefore, > > I don't think I can simply send_http_headers as type text/html... > > right, > > > > my $lookup = $r->lookup_uri( $uri ); > > > $r->send_http_header( 'text/html' ); > > so just change that line to: > $lookup->send_http_header; > > and you'll get the content-type and headers generated by the subrequest. > if there's a bug, it's in the book, subrequest->run() is not supposed to > include headers in the output. >
Re: send_http_header and subrequests
On Wed, 14 Jun 2000, Paul J. Lucas wrote: > The second example on p. 128 of the Eagle book sets the content > type and send the HTTP headers itself before running a > subrequest. > > However, on p. 468, the documentation for the run() method says > in part: > > When you invoke the subrequest's response handler in > this way, it will do everything a response handler is > supposed to, includinf sendinf the HTTP headers and the > document body. ... If you arevoking the subrequest > urn() method from within your own content handler, you > must not sen the HTTP headers and document body > yourself ... > > These seem to contradict each other. From testing, however, it > seems as though the example on p. 128 is correct and the > documentation on p. 468 isn't. Is this true? right, subrequest->run does not output headers. > my $sub_r = $r->lookup_file( $full_path ); > my $status = $sub_r->status(); > unless ( $status == DOCUMENT_FOLLOWS ) { > $r->log_error( "Can't look up $full_path" ); > return $status; > } > $r->send_http_header( $sub_r->content_type() ); does it help if you change that to: $sub_r->send_http_header; ?
Re: cgis and subrequests
On Sun, 20 Aug 2000, Alex Menendez wrote: > unfortunately, I am not entirely sure what a cgi is going to output all the > time. The cgi might try to do a redirect using the Location field. Therefore, > I don't think I can simply send_http_headers as type text/html... right, > > my $lookup = $r->lookup_uri( $uri ); > > $r->send_http_header( 'text/html' ); so just change that line to: $lookup->send_http_header; and you'll get the content-type and headers generated by the subrequest. if there's a bug, it's in the book, subrequest->run() is not supposed to include headers in the output.
Re: cgis and subrequests
unfortunately, I am not entirely sure what a cgi is going to output all the time. The cgi might try to do a redirect using the Location field. Therefore, I don't think I can simply send_http_headers as type text/html... thanx, though -amen Rick Myers wrote: > On Aug 20, 2000 at 19:38:53 -0700, Alex Menendez twiddled the keys to say: > > cgi scripts. the module uses lookup_uri() to generate a subrequest then > > calls run() to output the actual contents of the file. the eagle book > > says that calling run() on a subrequest should automatically send the > > client the appropriate http headers and the document's body. However, I > > have found that this is not the case. The following code does not send > > http headers for both cgis and html docs. The body stuff is working fine > > but the headers are not being sent: > > > > my $uri = $r->uri; > > unless(!$r->args) { > > $uri = $uri .'?'.$r->args; > > } > > my $subr = $r->lookup_uri($uri); > > if($r->dir_config('is_cgi')) { > > $subr->handler('cgi-script'); > > } else { > > $subr->handler('server-parsed'); > > } > > $subr->run(); > > my $status = $subr->status; > > $r->print(&create_img_tag($file,$SCRIPT_ON,$status)); > > return $status; > > > > any ideas? > > Yes. run() no longer sends headers (as far as I know). I don't know when > it was changed, but it pre-dates my experience. I've had the following > working just fine for close to a year now (or maybe my sense of time is > warped :). > > my $lookup = $r->lookup_uri( $uri ); > $r->send_http_header( 'text/html' ); > my $status = $lookup->run; > $r->status( $status ); > > Rick Myers[EMAIL PROTECTED] > > The Feynman Problem 1) Write down the problem. > Solving Algorithm 2) Think real hard. > 3) Write down the answer.
Re: cgis and subrequests
On Aug 20, 2000 at 19:38:53 -0700, Alex Menendez twiddled the keys to say: > cgi scripts. the module uses lookup_uri() to generate a subrequest then > calls run() to output the actual contents of the file. the eagle book > says that calling run() on a subrequest should automatically send the > client the appropriate http headers and the document's body. However, I > have found that this is not the case. The following code does not send > http headers for both cgis and html docs. The body stuff is working fine > but the headers are not being sent: > > my $uri = $r->uri; > unless(!$r->args) { > $uri = $uri .'?'.$r->args; > } > my $subr = $r->lookup_uri($uri); > if($r->dir_config('is_cgi')) { > $subr->handler('cgi-script'); > } else { > $subr->handler('server-parsed'); > } > $subr->run(); > my $status = $subr->status; > $r->print(&create_img_tag($file,$SCRIPT_ON,$status)); > return $status; > > any ideas? Yes. run() no longer sends headers (as far as I know). I don't know when it was changed, but it pre-dates my experience. I've had the following working just fine for close to a year now (or maybe my sense of time is warped :). my $lookup = $r->lookup_uri( $uri ); $r->send_http_header( 'text/html' ); my $status = $lookup->run; $r->status( $status ); Rick Myers[EMAIL PROTECTED] The Feynman Problem 1) Write down the problem. Solving Algorithm 2) Think real hard. 3) Write down the answer.
cgis and subrequests
Hello, all I have a module that appends a line of stats sensitive information to the bottom of html pages or cgi scripts. the module uses lookup_uri() to generate a subrequest then calls run() to output the actual contents of the file. the eagle book says that calling run() on a subrequest should automatically send the client the appropriate http headers and the document's body. However, I have found that this is not the case. The following code does not send http headers for both cgis and html docs. The body stuff is working fine but the headers are not being sent: my $uri = $r->uri; unless(!$r->args) { $uri = $uri .'?'.$r->args; } my $subr = $r->lookup_uri($uri); if($r->dir_config('is_cgi')) { $subr->handler('cgi-script'); } else { $subr->handler('server-parsed'); } $subr->run(); my $status = $subr->status; $r->print(&create_img_tag($file,$SCRIPT_ON,$status)); return $status; any ideas? BTW> &create_img_tag just returns a string. -amen
send_http_header and subrequests
The second example on p. 128 of the Eagle book sets the content type and send the HTTP headers itself before running a subrequest. However, on p. 468, the documentation for the run() method says in part: When you invoke the subrequest's response handler in this way, it will do everything a response handler is supposed to, includinf sendinf the HTTP headers and the document body. ... If you arevoking the subrequest urn() method from within your own content handler, you must not sen the HTTP headers and document body yourself ... These seem to contradict each other. From testing, however, it seems as though the example on p. 128 is correct and the documentation on p. 468 isn't. Is this true? The above aside, I'm having a problem when using subrequests when the subrequest also involves a (different) content handler. First, in a VirtualHost block, I have: AddType text/html .chtml SetHandlerperl-script PerlHandler +Apache::HTML::ClassParser that sets up the aforementioned "different" content handler that uses .chtml files to generate dynamic content pages. The ClassParser content handler, as expected, calls send_http_header() when it's ready to generate output. It does, in part: sub handler { # ... return DECLINED if $r->content_type ne 'text/html'; # ... $r->send_http_header(); # ... generate content ... return OK; } Using this content handler by itself works just fine; however, when I try to use it in conjunction with another content handler, things don't work right. Briefly, I have a Location block like: SetHandlerperl-script PerlHandler +My::Get that is a content handler that will, among other things, do on-the-fly conversions (similarly to the ImageMagick example in the Eagle book). The My::Get handler does, in part: my $sub_r = $r->lookup_file( $full_path ); my $status = $sub_r->status(); unless ( $status == DOCUMENT_FOLLOWS ) { $r->log_error( "Can't look up $full_path" ); return $status; } $r->send_http_header( $sub_r->content_type() ); return OK if $r->header_only(); return $sub_r->run(); When I use My::Get by itself, it works fine: it will correctly serve documents of any type. However, I'd like My::Get to simply be able to serve dynamic content pages if that's what it's asked to do to provide a uniform URL scheme. If $full_path refers to some .chtml file, things don't work right: I get two sets of response headers (200 OK) but the message that Apache prints is the canned "Document moved" error (with here, i.e., an empty URL). Things I tried: 1. In My::Get(), not calling send_http_header(). This results in ordinary documents not being served correctly, e.g., the content type is wrong. 2. In My::Get(), if $full_path ends up being a .chtml file, do: $r->filename( $full_path ); return DECLINED; This results in the correct headers; however, the raw HTML is served, i.e., the ClassParser handler is never called on the file. I looked in the Eagle book about calling send_http_header() from within subrequests by reading the documentation for is_initial_req() and is_main(), but neither says anything about send_http_header(). How can I get Apache to do what I want, i.e., have My::Get serve a file that is handled by another content handler? - Paul