Re: PerlTransHandler headaches
Glenn E. Bailey III wrote: Hello, While I am not new to Perl, I am completely new to mod_perl. check out the resources at http://perl.apache.org/ - there's lots of good information there :) sub handler { my $r = shift; return OK; } 1; And not matter what I always get a 404 with the following in the log: [Tue Jul 29 03:27:27 2003] [error] [client 10.0.0.1] File does not exist: / the translation phase is there to map the URI to a filename. by returning OK, you're telling Apache that you've done the translation (that is, you have set $r-filename to something useful). since you didn't set $r-filename, apache is returning 404, since it can't serve the value of $r-filename. so, the general rule for PerlTransHandlers is to return DECLINED unless you set $r-filename. chapter 12 in the mod_perl Developer's Cookbook deals specifically with the PerlTransHandler and is as good a place to start learning as any. HTH --Geoff
RE: PerlTransHandler headaches
: check out the resources at http://perl.apache.org/ - there's : lots of good : information there :) Heh, only found one document there concerning the TransHandler stuff .. : so, the general rule for PerlTransHandlers is to return : DECLINED unless you : set $r-filename. What I am trying to do is just test, to make sure it is working ok. So what I did is wrote the following snippit: sub handler { my $r = shift; return DECLINED; } That should still allow me to pull up my default content, correct? As of now it still gives me a 404 ..
Re: PerlTransHandler headaches
: so, the general rule for PerlTransHandlers is to return : DECLINED unless you : set $r-filename. What I am trying to do is just test, to make sure it is working ok. So what I did is wrote the following snippit: sub handler { my $r = shift; return DECLINED; } That should still allow me to pull up my default content, correct? As of now it still gives me a 404 .. make sure the request works without the PerlTransHandler installed first. if it does, then adding that routine should be ok. don't forget, you can't just change handlers and expect them to work - because the code is loaded the first time it's seen and not on every request, you either need to install Apache::StatINC, Apache::Reload, set PerlFreshRestart On and restart the server or (simplest) fully shutdown and startup the server. --Geoff
RE: PerlTransHandler headaches
: don't forget, you can't just change handlers and expect them : to work - This is probably what has been messing me up. Doing a quick stop and restart of Apache after any change I made seems to have fixed my problems, do! Thanks for your help ;-) . Glenn E. Bailey III . Network Solutions Developer . Sprocket Data, Inc.
Re: PerlTransHandler problem
* Rasoul Hajikhani [EMAIL PROTECTED] [2002-06-12 19:12]: Hello folks, I am trying to implement a simple PerlTransHandler to change: http://myserver/ to http://myserver.rhythm.com/ And here is my code: [-- snip --] Have you seen http://httpd.apache.org/docs/misc/rewriteguide.html? The first section is about URL layout, and the first example is about canonicalizing URLs. (darren) -- It has long been an axiom of mine that the little things are infinitely the most important. -- Arthur Conan Coyle
Re: PerlTransHandler problem
Quoting Rasoul Hajikhani ([EMAIL PROTECTED]): Hello folks, I am trying to implement a simple PerlTransHandler to change: http://myserver/ to http://myserver.rhythm.com/ And here is my code: package MIS::GENERAL::FixURL; use Apache::Constants qw(DECLINED); use strict; sub handler { my $r = shift; my $uri = $r-uri; return DECLINED if ($uri =~ m/^.+\.rhythm\.com$/) IIRC, the $r-uri method is normally not going yield the hostname or scheme (unless this is a proxy request). So for a request to http://www.rhythm.com/test/myfile.html $r-uri is going to return only /test/myfile.html You may want to do some logging to verify. Add use Apache::Log (); then inside your handler... my $log = $r-server-log; $log-debug(Processing request . $r-uri); Hope that helps. $uri=~ s/^(.+)/$1\.rhythm\.com/; $r-uri($uri); return DECLINED; } 1; Here is my https.conf entry: PerlTransHandler MIS::GENERAL::FixURL And here is my error when I type: s7.rhythm.com Invalid URI in request GET / HTTP/1.0 But I get no error with: http://s7/ Can some one tell me what am I doing wrong? Thanks in advance -r
Re: PerlTransHandler problem
Rasoul == Rasoul Hajikhani [EMAIL PROTECTED] writes: Rasoul I am trying to implement a simple PerlTransHandler to change: Rasoul http://myserver/ Rasoul to Rasoul http://myserver.rhythm.com/ Both of those are / as far as as $r-uri is concerned. What are you *really* trying to do? -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Re: PerlTransHandler problem
I am realy trying to make sure that all requests for http://myserver/ are treated as http://myserver.rhythm.com/ so that my other applications that depend on reading cookies down the request chain could actually do so... -r Randal L. Schwartz wrote: Rasoul == Rasoul Hajikhani [EMAIL PROTECTED] writes: Rasoul I am trying to implement a simple PerlTransHandler to change: Rasoul http://myserver/ Rasoul to Rasoul http://myserver.rhythm.com/ Both of those are / as far as as $r-uri is concerned. What are you *really* trying to do? -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Re: PerlTransHandler problem
A funny thing is happening with my PerlTransHandler... It is not being called at all... :( I have added warn messages but they never appear in the error log. I am at a loss and hoping that some one may have an answer... -r Lyle Brooks wrote: Quoting Rasoul Hajikhani ([EMAIL PROTECTED]): Hello folks, I am trying to implement a simple PerlTransHandler to change: http://myserver/ to http://myserver.rhythm.com/ And here is my code: package MIS::GENERAL::FixURL; use Apache::Constants qw(DECLINED); use strict; sub handler { my $r = shift; my $uri = $r-uri; return DECLINED if ($uri =~ m/^.+\.rhythm\.com$/) IIRC, the $r-uri method is normally not going yield the hostname or scheme (unless this is a proxy request). So for a request to http://www.rhythm.com/test/myfile.html $r-uri is going to return only /test/myfile.html You may want to do some logging to verify. Add use Apache::Log (); then inside your handler... my $log = $r-server-log; $log-debug(Processing request . $r-uri); Hope that helps. $uri=~ s/^(.+)/$1\.rhythm\.com/; $r-uri($uri); return DECLINED; } 1; Here is my https.conf entry: PerlTransHandler MIS::GENERAL::FixURL And here is my error when I type: s7.rhythm.com Invalid URI in request GET / HTTP/1.0 But I get no error with: http://s7/ Can some one tell me what am I doing wrong? Thanks in advance -r
Re: PerlTransHandler problem
You are only going to have Transhandlers defined in the main server or virtual host, not in any Location or Directory containers. Check and see if you have any other Transhandlers defined earlier in your httpd.conf file. If an earlier Transhandler returns OK, then later ones won't be called. Quoting Rasoul Hajikhani ([EMAIL PROTECTED]): A funny thing is happening with my PerlTransHandler... It is not being called at all... :( I have added warn messages but they never appear in the error log. I am at a loss and hoping that some one may have an answer... -r Lyle Brooks wrote: Quoting Rasoul Hajikhani ([EMAIL PROTECTED]): Hello folks, I am trying to implement a simple PerlTransHandler to change: http://myserver/ to http://myserver.rhythm.com/ And here is my code: package MIS::GENERAL::FixURL; use Apache::Constants qw(DECLINED); use strict; sub handler { my $r = shift; my $uri = $r-uri; return DECLINED if ($uri =~ m/^.+\.rhythm\.com$/) IIRC, the $r-uri method is normally not going yield the hostname or scheme (unless this is a proxy request). So for a request to http://www.rhythm.com/test/myfile.html $r-uri is going to return only /test/myfile.html You may want to do some logging to verify. Add use Apache::Log (); then inside your handler... my $log = $r-server-log; $log-debug(Processing request . $r-uri); Hope that helps. $uri=~ s/^(.+)/$1\.rhythm\.com/; $r-uri($uri); return DECLINED; } 1; Here is my https.conf entry: PerlTransHandler MIS::GENERAL::FixURL And here is my error when I type: s7.rhythm.com Invalid URI in request GET / HTTP/1.0 But I get no error with: http://s7/ Can some one tell me what am I doing wrong? Thanks in advance -r
Re: PerlTransHandler problem
Sounds like it's more of a DNS issue than a modperl issue. Depending on what your motivation for requiring the full name, you may also explicitly set ServerName myserver.rhythm.com UseCanonicalName off Quoting Rasoul Hajikhani ([EMAIL PROTECTED]): I am realy trying to make sure that all requests for http://myserver/ are treated as http://myserver.rhythm.com/ so that my other applications that depend on reading cookies down the request chain could actually do so... -r Randal L. Schwartz wrote: Rasoul == Rasoul Hajikhani [EMAIL PROTECTED] writes: Rasoul I am trying to implement a simple PerlTransHandler to change: Rasoul http://myserver/ Rasoul to Rasoul http://myserver.rhythm.com/ Both of those are / as far as as $r-uri is concerned. What are you *really* trying to do? -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Re: PerlTransHandler problem
Quoting Lyle Brooks ([EMAIL PROTECTED]): Sounds like it's more of a DNS issue than a modperl issue. Depending on what your motivation for requiring the full name, you may also explicitly set ServerName myserver.rhythm.com UseCanonicalName off errr... should be UseCanonicalName On Quoting Rasoul Hajikhani ([EMAIL PROTECTED]): I am realy trying to make sure that all requests for http://myserver/ are treated as http://myserver.rhythm.com/ so that my other applications that depend on reading cookies down the request chain could actually do so... -r Randal L. Schwartz wrote: Rasoul == Rasoul Hajikhani [EMAIL PROTECTED] writes: Rasoul I am trying to implement a simple PerlTransHandler to change: Rasoul http://myserver/ Rasoul to Rasoul http://myserver.rhythm.com/ Both of those are / as far as as $r-uri is concerned. What are you *really* trying to do? -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Re: PerlTransHandler problem
What it sounds like you want is: PerlTransHandler Whatever::CheckName and in CheckName.pm sub handler { my $r = instance Apache::Request(shift); if ($r-hostname !~ /rhythm\.com/) { $r-header_out(Location = http://myserver.rhythm.com.$r-uri); return REDIRECT; } else { redirect DECLINED; } } --- A redirect rule (using the Rewrite Engine) would probably be easier and better yet. simran. Quoting Rasoul Hajikhani ([EMAIL PROTECTED]): Hello folks, I am trying to implement a simple PerlTransHandler to change: http://myserver/ to http://myserver.rhythm.com/ And here is my code: package MIS::GENERAL::FixURL; use Apache::Constants qw(DECLINED); use strict; sub handler { my $r = shift; my $uri = $r-uri; return DECLINED if ($uri =~ m/^.+\.rhythm\.com$/) IIRC, the $r-uri method is normally not going yield the hostname or scheme (unless this is a proxy request). So for a request to http://www.rhythm.com/test/myfile.html $r-uri is going to return only /test/myfile.html You may want to do some logging to verify. Add use Apache::Log (); then inside your handler... my $log = $r-server-log; $log-debug(Processing request . $r-uri); Hope that helps. $uri=~ s/^(.+)/$1\.rhythm\.com/; $r-uri($uri); return DECLINED; } 1; Here is my https.conf entry: PerlTransHandler MIS::GENERAL::FixURL And here is my error when I type: s7.rhythm.com Invalid URI in request GET / HTTP/1.0 But I get no error with: http://s7/ Can some one tell me what am I doing wrong? Thanks in advance -r
RE: PerlTransHandler and CGI.pm
Got it... Seems like the query string is decoded twice: Therefore http://biodoc.ch/de/search;query=%252Btest+%252Bdna+-xyz works perfectly, since all the '%' are encoded. Then it even works with slashes :-) -- Eric Jain When processing the url http://biodoc.ch/de/search?query=%2Btest+%2Bdna+-xyz , $cgi-param('query') correctly returns '+test +dna -xyz'. But if I use http://biodoc.ch/de/search;query=%2Btest+%2Bdna+-xyz instead, I get ' test dna -xyz'. If I include a %3F (=?) in the url, I even get a 404 error. Slashes too only work if they are not encoded. There must be something wrong in my PerlTransHandler, approximatly here: my $uri = $r-uri(); if ( my($u1,$u2) = $uri =~ / ^ ([^?]+?) ; ([^?]*) $ /x ) { $r-uri($u1); $r-args($u2); } But what? -- Eric Jain
Re: PerlTransHandler
On Thu, 25 May 2000, Sergey Ivanyuk wrote: Hi All. I'm having problems with the PerlTransHandler handler. I would like to only translate some requests, but keep Aliases working. However, I just can't get that done. If I use a simple 'return DECLINED;', all my cgi scripts and aliases directories return 'Not found'. I know the handler is executed, and if I remove it from httpd.conf, everything works fine. What am I doing wrong? Should a simple 'return DECLINED;' run default handlers, or am I missing something? Thanks in advance. return DECLINED; should work fine. can you post a tiny example config and handler? Apache::ShowRequest (part of the Apache::Module package on CPAN) can also help debug this sort of problem.
Re: PerlTransHandler
I'm having problems with the PerlTransHandler handler. I would like to only translate some requests, but keep Aliases working. However, I just can't get that done. If I use a simple 'return DECLINED;', all my cgi scripts and aliases directories return 'Not found'. I know the handler is executed, and if I remove it from httpd.conf, everything works fine. What am I doing wrong? Should a simple 'return DECLINED;' run default handlers, or am I missing something? Thanks in advance. return DECLINED; should work fine. can you post a tiny example config and handler? Apache::ShowRequest (part of the Apache::Module package on CPAN) can also help debug this sort of problem. A little more information. Originally, I was trying this on Redhat 5.2, now just tried it on 6.2 with stock apache and stock mod_perl. Same result. I've added the line marked by + to the default httpd.conf: -- IfModule mod_perl.c + PerlTransHandler handler Alias /perl/ /home/httpd/perl/ Location /perl SetHandler perl-script -- This is my handler.pm: -- #!/usr/bin/perl package handler; use Apache; sub handler { return DECLINED; } 1; -- With this config, no requests work. Not even a request to the root of the server, which has the default apache test page installed. If I remove the PerlTransHandler line from the config and restart apache, everything works. There are the stats from the box I've tried it on: -- [modemch@rabox4 modemch]$ rpm -qa | grep 'apache\|mod_perl' apache-1.3.12-2 mod_perl-1.21-10 [modemch@rabox4 modemch]$ uname -a Linux rabox4.eventsdigital.com 2.2.14-5.0 #1 Tue Mar 7 20:53:41 EST 2000 i586 unknown [modemch@rabox4 modemch]$ cat /etc/issue Red Hat Linux release 6.2 (Zoot) Kernel 2.2.14-5.0 on an i586 [modemch@rabox4 modemch]$ -- I really really need to get to the bottom of this. Thanks for all your help.
Re: PerlTransHandler
On Thu, 25 May 2000, Sergey Ivanyuk wrote: package handler; use Apache; sub handler { return DECLINED; } where does DECLINED come from? watch what happens if you add 'print handler()' and run it from the command line, and watch what happens when you add 'use strict;'. adding 'use Apache::Constants qw(DECLINED)' will fix your problem.
RE: PerlTransHandler question.
time to pick up the Eagle book... check out http://www.modperl.com/ specifically http://www.modperl.com/book/chapters/ch7.html#The_URI_Translation_Phase HTH --Geoff -Original Message-From: Antonio Pascual [mailto:[EMAIL PROTECTED]]Sent: Tuesday, May 23, 2000 9:59 AMTo: [EMAIL PROTECTED]Subject: PerlTransHandler question. I want handler a request only if the url is like http://localhost/idTrans=XXX In other case do the default behaviour. How could I do this? I suppose that I have to use PerlTransHandler, but I don't know how. Thanks in advance. Antonio.
Re: PerlTransHandler question.
"Antonio" == Antonio Pascual [EMAIL PROTECTED] writes: Antonio I want handler a request only if the url is like http://localhost/idTrans=XXX Antonio In other case do the default behaviour. Antonio How could I do this? Antonio I suppose that I have to use PerlTransHandler, but I don't know how. Nahh. Use basic core functionality, in your top-level conf file: LocationMatch "^/idTrans=" SetHandler perl-script PerlHandler My::Handler /LocationMatch -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
RE: PerlTransHandler and Files ~ .. sort of mapping
hi, I was wondering how to map PerlTransHandler only for certain type of files. ( I'm doing URI rewriting not URI-filename translation ?!!) Something like : Location Files ~ "xml$" PerlTransHandler Apache::MyHandler /Files /Location Yes I know this is wrong...can this be done in some other way ? Yes, it's wrong because the job of the translation phase is precisely to translate from url to file, therefore it cannot operate on files! PerlTransHandler Apache::MyHandler ... sub handler { my $r = shift; return DECLINED unless $r-uri =~ /\.xml$/; ... } -- Eric
Re: PerlTransHandler
On Tue, 19 Oct 1999, Mark Cogan wrote: On Tuesday, October 19, 1999 4:13 AM, William Deegan [SMTP:[EMAIL PROTECTED]] wrote: How can I change the environment variables that get passed to a perl script running under Apache::Registry from a PerlTransHandler? I'm using the PerlTransHandler to do a sort of dynamic mod_rewrite functionality. [...] Use the %ENV hash in perl. The environment is shared between the whole request, so setting $ENV{whatever} in the PerlTransHandler will make it visible to the content handler down the line. I'd suggest using $r-subprocess_env() instead. We have a somewhat similar situation where we have a PerlTransHandler that sets certain environment variables that CGI scripts depend on (yes, plain mod_cgi while we have mod_perl -- but that's another story). I guess %ENV will work in many situations, but it might bite you later when you can't figure out why a particular env variable isn't getting set in certain situations (speaking from experience). See the explanation on pages 454-455 in the Eagle book.
Re: PerlTransHandler
"Dan" == Dan Rench [EMAIL PROTECTED] writes: Dan I'd suggest using $r-subprocess_env() instead. I was going to suggest that too. %ENV controls the environment of the currently running Perl process, but child processes come from the "subprocess env", which only the call above sets. -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Re: PerlTransHandler
At 10:03 AM 10/19/99 -0700, William Deegan wrote: Eric Cholet wrote: On Tuesday, October 19, 1999 4:13 AM, William Deegan [SMTP:[EMAIL PROTECTED]] wrote: How can I change the environment variables that get passed to a perl script running under Apache::Registry from a PerlTransHandler? I'm using the PerlTransHandler to do a sort of dynamic mod_rewrite functionality. Since you've got mod_perl on both sides, I'd suggest you don't use env variables (which are expensive). Your Trans handler can just set package variables which will be picked up by the registry script. Alternatives are using $r-dir_config, or $r-notes. I'll look into that. For now though all of our scripts are set up to check for an enviroment variable set for some virtual hosts, now we'd like a way to set these same variables using a PerlTransHandler. So how do I go about setting the enviroment variables. Assuming that I don't care about the cost. Use the %ENV hash in perl. The environment is shared between the whole request, so setting $ENV{whatever} in the PerlTransHandler will make it visible to the content handler down the line. --- Mark Cogan[EMAIL PROTECTED] Director of Engineering +1 520-881-8101 ArtToday www.arttoday.com
Re: PerlTransHandler
Eric Cholet wrote: On Tuesday, October 19, 1999 4:13 AM, William Deegan [SMTP:[EMAIL PROTECTED]] wrote: How can I change the environment variables that get passed to a perl script running under Apache::Registry from a PerlTransHandler? I'm using the PerlTransHandler to do a sort of dynamic mod_rewrite functionality. Since you've got mod_perl on both sides, I'd suggest you don't use env variables (which are expensive). Your Trans handler can just set package variables which will be picked up by the registry script. Alternatives are using $r-dir_config, or $r-notes. I'll look into that. For now though all of our scripts are set up to check for an enviroment variable set for some virtual hosts, now we'd like a way to set these same variables using a PerlTransHandler. So how do I go about setting the enviroment variables. Assuming that I don't care about the cost. Thanks, Bill - Buy and sell safely on the Internet with i-Escrow. For details visit http://www.iescrow.com/ - begin:vcard n:Deegan;William tel;fax:650-638-7890 tel;work:650-638-7975 x-mozilla-html:FALSE url:http://www.iescrow.com org:iEscrow,Inc. version:2.1 email;internet:[EMAIL PROTECTED] title:Web Site Operations Manager note:http://www.orangefood.com/baddog adr;quoted-printable:;;1730 South Amphlett Blvd=0D=0ASuite 215;San Mateo;CA;94402; x-mozilla-cpt:;18272 fn:William Deegan end:vcard