Using a handler other than 'handler'
Hello, I apologize for such a trivial question, but I'd like to use a function other than handler as a perl handler. According to the doc, it was possible in mod_perl 1, but I can't manage to get it to work under mod_perl 2. Here is an example of my code: file Authen.pm sub handler { // regular handling } sub special { // special case } file httpd.conf Location /perl/ PerlAuthenHandler /lib/Authen /Location Location /perl/special-case/ # I want to override the regular case by using special instead of handler in /lib/Authen.pm /Location Thanks in advance, Cédric Bertolini
Re: Using a handler other than 'handler'
@Michel, Thanks for the reply. As far as I know, Apache2::RequestRec is a module that provides several functions to manage the $request object provided by mod_perl (http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html). It's not really a handler, though most handlers use this module one way or another. I just want to use a different handler than usual, but from the same file, If that's possible. @Nico Thanks for the reply. Deciding on a behavior based on $r-uri or $r-filename in the handler is what I was doing previously, but I'd love to have a solution based the config file instead of the handler itself, for robustness. I will have to stick to this solution if mod_perl doesn't let me provide the name of the handler, though. 2010/9/27 Nico Coetzee nicc...@gmail.com I had a similar requirement. My solution: based on the value of $r-uri() I would call the different subs from the main handler() sub. All the other subs take $r as the first argument and then the rest of the parameters follow. Probably not the best solution, but it worked for me. Cheers Nico 2010/9/27 Cédric Bertolini bertolini.ced...@gmail.com Hello, I apologize for such a trivial question, but I'd like to use a function other than handler as a perl handler. According to the doc, it was possible in mod_perl 1, but I can't manage to get it to work under mod_perl 2. Here is an example of my code: file Authen.pm sub handler { // regular handling } sub special { // special case } file httpd.conf Location /perl/ PerlAuthenHandler /lib/Authen /Location Location /perl/special-case/ # I want to override the regular case by using special instead of handler in /lib/Authen.pm /Location Thanks in advance, Cédric Bertolini
Re: Using a handler other than 'handler'
Hi. You can use PerlAuthenhandler Your::Module-special See http://perl.apache.org/docs/2.0/user/coding/coding.html#Techniques Cédric Bertolini wrote: @Michel, Thanks for the reply. As far as I know, Apache2::RequestRec is a module that provides several functions to manage the $request object provided by mod_perl (http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html). It's not really a handler, though most handlers use this module one way or another. I just want to use a different handler than usual, but from the same file, If that's possible. @Nico Thanks for the reply. Deciding on a behavior based on $r-uri or $r-filename in the handler is what I was doing previously, but I'd love to have a solution based the config file instead of the handler itself, for robustness. I will have to stick to this solution if mod_perl doesn't let me provide the name of the handler, though. 2010/9/27 Nico Coetzee nicc...@gmail.com I had a similar requirement. My solution: based on the value of $r-uri() I would call the different subs from the main handler() sub. All the other subs take $r as the first argument and then the rest of the parameters follow. Probably not the best solution, but it worked for me. Cheers Nico 2010/9/27 Cédric Bertolini bertolini.ced...@gmail.com Hello, I apologize for such a trivial question, but I'd like to use a function other than handler as a perl handler. According to the doc, it was possible in mod_perl 1, but I can't manage to get it to work under mod_perl 2. Here is an example of my code: file Authen.pm sub handler { // regular handling } sub special { // special case } file httpd.conf Location /perl/ PerlAuthenHandler /lib/Authen /Location Location /perl/special-case/ # I want to override the regular case by using special instead of handler in /lib/Authen.pm /Location Thanks in advance, Cédric Bertolini
Re: Using a handler other than 'handler'
@John Thanks for the reply, but PerlAuthenHandler Authen::special doesn't work. It worked in mod_perl 1, but mod_perl 2 complains that it can't find Authen/special.pm in @INC. @André, Thanks for the reply. I was reluctant to use this solution because of the OOC orientation of this syntax, but it isn't actually mandatory to define a class in order to use this. You just have to be aware that the custom handler will receive the request object as its second argument instead of the first. --- package Authen; sub handler { my ($r) = @_; # regular case with $r as the request object } sub special { my (undef, $r) = @_; # special case with $r as the request object } --- PerlAuthenHandler Authen-special --- Cheers, Cédric Bertolini 2010/9/27 André Warnier a...@ice-sa.com Hi. You can use PerlAuthenhandler Your::Module-special See http://perl.apache.org/docs/2.0/user/coding/coding.html#Techniques Cédric Bertolini wrote: @Michel, Thanks for the reply. As far as I know, Apache2::RequestRec is a module that provides several functions to manage the $request object provided by mod_perl (http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html). It's not really a handler, though most handlers use this module one way or another. I just want to use a different handler than usual, but from the same file, If that's possible. @Nico Thanks for the reply. Deciding on a behavior based on $r-uri or $r-filename in the handler is what I was doing previously, but I'd love to have a solution based the config file instead of the handler itself, for robustness. I will have to stick to this solution if mod_perl doesn't let me provide the name of the handler, though. 2010/9/27 Nico Coetzee nicc...@gmail.com I had a similar requirement. My solution: based on the value of $r-uri() I would call the different subs from the main handler() sub. All the other subs take $r as the first argument and then the rest of the parameters follow. Probably not the best solution, but it worked for me. Cheers Nico 2010/9/27 Cédric Bertolini bertolini.ced...@gmail.com Hello, I apologize for such a trivial question, but I'd like to use a function other than handler as a perl handler. According to the doc, it was possible in mod_perl 1, but I can't manage to get it to work under mod_perl 2. Here is an example of my code: file Authen.pm sub handler { // regular handling } sub special { // special case } file httpd.conf Location /perl/ PerlAuthenHandler /lib/Authen /Location Location /perl/special-case/ # I want to override the regular case by using special instead of handler in /lib/Authen.pm /Location Thanks in advance, Cédric Bertolini
All responses are 200 (server error)
Hi - don't know if anybody else have come across this. I have a mod_perl instance that produces output just as it should (checked in the logs and I even written the output to file just to have an extra check). The tcpdump also show everything is ok. BUT The content has the following HTML appended at the end: !DOCTYPE HTML PUBLIC -//IETF//DTD HTML 2.0//EN htmlhead title200 OK/title /headbody h1OK/h1 pThe server encountered an internal error or misconfiguration and was unable to complete your request./p pPlease contact the server administrator, webmas...@host.example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error./p pMore information about this error may be available in the server error log./p hr addressApache/2.2.3 (CentOS) Server at webdavtest Port 81/address /body/html So, I've enabled debug level logging everywhere and even enabled diagnostics in the mod_perl script. Nothing strange shows up anywhere. I even tried to change the return code with return Apache2::Const::XXX (XXX could be anything) but the return code is ALWAYS 200 with the above HTML appended to what ever output is sent to the browser. I also noted that the content length header is correct for the content sent to the browser and does not include the additional HTML above, but it still confuses the browser. Any ideas? Environment: CentOS 5.5 OS with the following packages: * httpd-2.2.3-43.el5.centos.3 * mod_perl-2.0.4-6.el5 In my config I have the following enabled: * LogLevel debug * PerlWarn On Thanks Nico
Re: All responses are 200 (server error)
Are you returning the value of 200 within a module you've written? I encountered a similar issue within a C module specific to valid requests. It was resolved by returning the internal constant OK. On Sep 27, 2010, at 5:27, Nico Coetzee nicc...@gmail.com wrote: Hi - don't know if anybody else have come across this. I have a mod_perl instance that produces output just as it should (checked in the logs and I even written the output to file just to have an extra check). The tcpdump also show everything is ok. BUT The content has the following HTML appended at the end: !DOCTYPE HTML PUBLIC -//IETF//DTD HTML 2.0//EN htmlhead title200 OK/title /headbody h1OK/h1 pThe server encountered an internal error or misconfiguration and was unable to complete your request./p pPlease contact the server administrator, webmas...@host.example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error./p pMore information about this error may be available in the server error log./p hr addressApache/2.2.3 (CentOS) Server at webdavtest Port 81/address /body/html So, I've enabled debug level logging everywhere and even enabled diagnostics in the mod_perl script. Nothing strange shows up anywhere. I even tried to change the return code with return Apache2::Const::XXX (XXX could be anything) but the return code is ALWAYS 200 with the above HTML appended to what ever output is sent to the browser. I also noted that the content length header is correct for the content sent to the browser and does not include the additional HTML above, but it still confuses the browser. Any ideas? Environment: CentOS 5.5 OS with the following packages: * httpd-2.2.3-43.el5.centos.3 * mod_perl-2.0.4-6.el5 In my config I have the following enabled: * LogLevel debug * PerlWarn On Thanks Nico
Apache::Template / Apache::Request
Hello, I'm having issues installing Apache::Request which has been asked for when I tried to build Apache::Template. See below: ch...@debian:~/Apache-Template-2.00_01$ perl Makefile.PL Warning: prerequisite Apache2::Request 0 not found. Writing Makefile for Apache::Template When I try to build Apache::Request (libapreq2-2.12) it appears to complete but something must not be quite right otherwise Apache::Template would be able to find it. Also doing instmodsh l doesn't list the module as installed. I came across this post and followed the instructions... http://www.perlmonks.org/?node_id=791589 I initially wasn't sure what like in the configure script I should have been editing but if you pass the location of apxs2 as follows that error goes away: ./configure --with-apache2-apxs=/usr/bin/apxs2 Heres the output during the build process: ch...@debian:~/libapreq2-2.12$ ./configure --with-apache2=/usr/bin/apxs2 perl: 5.10.0 ok mod_perl2: 2.04 ok Apache::Test: 1.31 ok ExtUtils::MakeMaker: 6.42 ok ExtUtils::XSBuilder: 0.28 ok Test::More: 0.72 ok ./configure --enable-perl-glue --with-apache2-apxs=/usr/bin/apxs2 --with-perl=/usr/bin/perl checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... no checking for mawk... mawk checking whether make sets $(MAKE)... yes checking whether make sets $(MAKE)... (cached) yes checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for style of include used by make... GNU checking dependency style of gcc... gcc3 checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking for a sed that does not truncate output... /bin/sed checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for ld used by gcc... /usr/bin/ld checking if the linker (/usr/bin/ld) is GNU ld... yes checking for /usr/bin/ld option to reload object files... -r checking for BSD-compatible nm... /usr/bin/nm -B checking whether ln -s works... yes checking how to recognise dependent libraries... pass_all checking how to run the C preprocessor... gcc -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking dlfcn.h usability... yes checking dlfcn.h presence... yes checking for dlfcn.h... yes checking for g++... no checking for c++... no checking for gpp... no checking for aCC... no checking for CC... no checking for cxx... no checking for cc++... no checking for cl.exe... no checking for FCC... no checking for KCC... no checking for RCC... no checking for xlC_r... no checking for xlC... no checking whether we are using the GNU C++ compiler... no checking whether g++ accepts -g... no checking dependency style of g++... none checking for g77... no checking for xlf... no checking for f77... no checking for frt... no checking for pgf77... no checking for cf77... no checking for fort77... no checking for fl32... no checking for af77... no checking for xlf90... no checking for f90... no checking for pgf90... no checking for pghpf... no checking for epcf90... no checking for gfortran... no checking for g95... no checking for xlf95... no checking for f95... no checking for fort... no checking for ifort... no checking for ifc... no checking for efc... no checking for pgf95... no checking for lf95... no checking for ftn... no checking whether we are using the GNU Fortran 77 compiler... no checking whether accepts -g... no checking the maximum length of command line arguments... 32768 checking command to parse /usr/bin/nm -B output from gcc object... ok checking for objdir... .libs checking for ar... ar checking for ranlib... ranlib checking for strip... strip checking if gcc supports -fno-rtti -fno-exceptions... no checking for gcc option to produce PIC... -fPIC checking if gcc PIC flag -fPIC works... yes checking if gcc static flag -static works... yes checking if gcc supports -c -o file.o... yes checking whether the gcc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping
Re: Using a handler other than 'handler'
On 09/27/2010 05:17 AM, Cédric Bertolini wrote: PerlAuthenHandler Authen::special doesn't work. It worked in mod_perl 1, but mod_perl 2 complains that it can't find Authen/special.pm http://special.pm in @INC. That's not what he suggested. He said: PerlAuthenHandler Authen-special Try that and see if it works -- Michael Peters Plus Three, LP
Re: Apache::Template / Apache::Request
Hi Chris, On Mon, Sep 27, 2010 at 9:41 AM, Chris Ray ch...@rayjchris.co.uk wrote: Hello, I'm having issues installing Apache::Request which has been asked for when I tried to build Apache::Template. My recommendation at this point would be to stop using Apache::Template. It's not maintained anymore, and I don't think anyone is using it with mod_perl 2. It's pretty simple to write a basic handler that runs templates, or you could take over Apache::Template if you like, but I think the extra stuff in Apache::Template that adds directives to httpd.conf is probably more trouble than it's worth. - Perrin
Fwd: All responses are 200 (server error)
Oops - seems I didn't include the group on my reply FYI Here is another test I did (simpler) Apache Config PerlModule FNBC::test_statusline PerlWarn On Location /test1 SetHandler perl-script PerlResponseHandler FNBC::test_statusline /Location test_statusline.pm package FNBC::test_statusline; use strict; use warnings; use Apache2::Access (); use Apache2::RequestUtil (); use Apache2::RequestRec (); use Apache2::Const -compile = qw( OK ); sub handler { my $r = shift; $r-status_line(499 We have been FooBared); $r-err_headers_out-add( 'X-Testing' = 'True' ); $r-content_type( text/html ); my $body = htmlheadtitleTesting/title/headbodyh3It really does work.../h3/body/html; $r-set_content_length( length( $body ) ); $r-print( $body ); return Apache2::Const::OK; } 1; Trace GET /test1/sdjakgd HTTP/1.1 Host: webdavtest:81 User-Agent: Links (2.2; Linux 2.6.32-24-generic x86_64; 210x65) Accept: */* Accept-Encoding: gzip, deflate Accept-Charset: us-ascii, ISO-8859-1, ISO-8859-2, ISO-8859-3, ISO-8859-4, ISO-8859-5, ISO-8859-6, ISO-8859-7, ISO-8859-8, ISO-8859-9, ISO-8859-10, ISO-8859-13, ISO-8859-14, ISO-8859-15, ISO-8859-16, windows-1250, windows-1251, windows-1252, windows-1256, windows-1257, cp437, cp737, cp850, cp852, cp866, x-cp866-u, x-mac, x-mac-ce, x-kam-cs, koi8-r, koi8-u, koi8-ru, TCVN-5712, VISCII, utf-8 Accept-Language: en, *;q=0.1 Connection: Keep-Alive HTTP/1.1 200 OK Date: Tue, 28 Sep 2010 06:06:13 GMT Server: Apache/2.2.3 (CentOS) X-Testing: True Content-Length: 92 Connection: close Content-Type: text/html; charset=UTF-8 htmlheadtitleTesting/title/headbodyh3It really does work.../h3/body/html I really would like to know why I can not set the status line I followed the example from http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_status_line_ Thanks Nico
Re: Fwd: All responses are 200 (server error)
Two thoughts... try status 400 (might be special handling for 4xx unknown) try r-status instead of/in addition to just r-status_line?
Re: Fwd: All responses are 200 (server error)
The status 400 (with $r-status_line) produces the same result HTTP/1.1 200 OK and with ($r-status) is creates a HTTP/1.1 400 Bad Request (the custom string gets lost) The $r-status with a code of 499 produces a HTTP/1.1 400 Bad Request On Tue, Sep 28, 2010 at 6:31 AM, William A. Rowe Jr. wr...@rowe-clan.netwrote: Two thoughts... try status 400 (might be special handling for 4xx unknown) try r-status instead of/in addition to just r-status_line?