You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by re...@ya.ru on 2012/07/02 01:50:39 UTC

Modperl handler status code. Handler invoked two times per request.

 Hello.

 I've found unexpected behavior of modperl handler. If handler return
 Apache2::Const::HTTP_OK status all is ok. But other HTTP_*
 status code (tested with Apache2::Const::HTTP_NOT_FOUND;
 Apache2::Const::HTTP_FORBIDDEN and Apache2::Const::SERVER_ERROR)
 invoke handler again.

 Configuration:

<VirtualHost *:80>
    DocumentRoot "/srv/http/err/htdocs"
    ServerName err.localhost
    SetHandler 		perl-script

    PerlRequire /srv/http/err/htdocs/Main.pm
    PerlResponseHandler	XYZ::Main
</VirtualHost>

 Module:
   package XYZ::Main;

   use strict;
   use APR::Table;
   use Apache2::RequestRec ();
   use Apache2::RequestIO ();
   use Apache2::Const -compile => qw/:common :http/;
   use CGI;

   sub handler{
     `echo "call" >>/tmp/inv`;
     return Apache2::Const::OK;
     return Apache2::Const::HTTP_OK;
     return Apache2::Const::HTTP_NOT_FOUND;
   }

  1;

 Mainly, in some cases I want to show Apache2
 default pages (like for HTTP_NOF_FOUND and HTTP_SERVER_ERROR) and
 don't know right way to implement that. It seems that similar
 Apache2::Const::HTTP* status code from handler is a good way but now I
 have to use method-handler technique
 (https://perl.apache.org/docs/2.0/user/coding/coding.html#Method_Handlers)
 to avoid second handler invocations.

 So, whats wrong?

 Regards,
 Nick.

===
Apache/2.2.22 (Unix) DAV/2 PHP/5.4.4 mod_perl/2.0.7 Perl/v5.16.0 Server
at err.localhost Port 80Server version: Apache/2.2.22 (Unix)

Re: Modperl handler status code. Handler invoked two times per request.

Posted by Vincent Veyron <vv...@wanadoo.fr>.
Le lundi 02 juillet 2012 à 03:50 +0400, reisub@ya.ru a écrit :
> Hello.

Hi,


>  So, whats wrong?
> 

Dude, a lot of things... 

Not sure I can catch them all, but since nobody is tackling it, see some
comments below. 

>  I've found unexpected behavior of modperl handler. If handler return
>  Apache2::Const::HTTP_OK status all is ok. 

? I get an error code with this, after the 200 OK, so I'm surprised it
works for you

> But other HTTP_*
>  status code (tested with Apache2::Const::HTTP_NOT_FOUND;
>  Apache2::Const::HTTP_FORBIDDEN and Apache2::Const::SERVER_ERROR)
>  invoke handler again.
> 

I don't see this

>  Configuration:
> 
> <VirtualHost *:80>
>     DocumentRoot "/srv/http/err/htdocs"
>     ServerName err.localhost
>     SetHandler 		perl-script
> 

I think the following should be PerlModule instead of PerlRequire?

>     PerlRequire /srv/http/err/htdocs/Main.pm

I would wrap the following into a Location directive

>     PerlResponseHandler	XYZ::Main


> </VirtualHost>
> 
>  Module:
>    package XYZ::Main;
> 
>    use strict;

the following line is unneeded

>    use APR::Table;

the following line is unneeded

>    use Apache2::RequestRec ();

the following line is unneeded

>    use Apache2::RequestIO ();

this one is needed

>    use Apache2::Const -compile => qw/:common :http/;

the following line is unneeded

>    use CGI;
> 
>    sub handler{
>      `echo "call" >>/tmp/inv`;

this works

>      return Apache2::Const::OK;

the following lines won't happen after the first return

>      return Apache2::Const::HTTP_OK;
>      return Apache2::Const::HTTP_NOT_FOUND;
>    }
> 
>   1;
> 
>  Mainly, in some cases I want to show Apache2
>  default pages (like for HTTP_NOF_FOUND and HTTP_SERVER_ERROR) and
>  don't know right way to implement that. It seems that similar
>  Apache2::Const::HTTP* status code from handler is a good way but now I
>  have to use method-handler technique
>  (https://perl.apache.org/docs/2.0/user/coding/coding.html#Method_Handlers)
>  to avoid second handler invocations.

It seems to me like you are copy/pasting code and hoping it will work.

I suggest you invest some time in the documentation first, like reading
this throughout :

https://perl.apache.org/docs/2.0/user/index.html

It's worth it.


-- 
Vincent Veyron
http://vincentveyron.com/
Logiciels de gestion des sinistres assurances et des dossiers contentieux pour le service juridique



Re: Modperl handler status code. Handler invoked two times per request.

Posted by Vincent Veyron <vv...@wanadoo.fr>.
Le lundi 02 juillet 2012 à 03:50 +0400, reisub@ya.ru a écrit :
> Hello.

Hi,


>  So, whats wrong?
> 

Dude, a lot of things... 

Not sure I can catch them all, but since nobody is tackling it, see some
comments below. 

>  I've found unexpected behavior of modperl handler. If handler return
>  Apache2::Const::HTTP_OK status all is ok. 

? I get an error code with this, after the 200 OK, so I'm surprised it
works for you

> But other HTTP_*
>  status code (tested with Apache2::Const::HTTP_NOT_FOUND;
>  Apache2::Const::HTTP_FORBIDDEN and Apache2::Const::SERVER_ERROR)
>  invoke handler again.
> 

I don't see this

>  Configuration:
> 
> <VirtualHost *:80>
>     DocumentRoot "/srv/http/err/htdocs"
>     ServerName err.localhost
>     SetHandler 		perl-script
> 

I think the following should be PerlModule instead of PerlRequire?

>     PerlRequire /srv/http/err/htdocs/Main.pm

I would wrap the following into a Location directive

>     PerlResponseHandler	XYZ::Main


> </VirtualHost>
> 
>  Module:
>    package XYZ::Main;
> 
>    use strict;

the following line is unneeded

>    use APR::Table;

the following line is unneeded

>    use Apache2::RequestRec ();

the following line is unneeded

>    use Apache2::RequestIO ();

this one is needed

>    use Apache2::Const -compile => qw/:common :http/;

the following line is unneeded

>    use CGI;
> 
>    sub handler{
>      `echo "call" >>/tmp/inv`;

this works

>      return Apache2::Const::OK;

the following lines won't happen after the first return

>      return Apache2::Const::HTTP_OK;
>      return Apache2::Const::HTTP_NOT_FOUND;
>    }
> 
>   1;
> 
>  Mainly, in some cases I want to show Apache2
>  default pages (like for HTTP_NOF_FOUND and HTTP_SERVER_ERROR) and
>  don't know right way to implement that. It seems that similar
>  Apache2::Const::HTTP* status code from handler is a good way but now I
>  have to use method-handler technique
>  (https://perl.apache.org/docs/2.0/user/coding/coding.html#Method_Handlers)
>  to avoid second handler invocations.

It seems to me like you are copy/pasting code and hoping it will work.

I suggest you invest some time in the documentation first, like reading
this throughout :

https://perl.apache.org/docs/2.0/user/index.html

It's worth it.


-- 
Vincent Veyron
http://vincentveyron.com/
Logiciels de gestion des sinistres assurances et des dossiers contentieux pour le service juridique