You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Bernard Nauwelaerts <bp...@it-development.be> on 2003/05/17 22:27:08 UTC

[QUESTION] - Strange Apache error handling

Hi all !

I'm building a dynamic website using mod_perl ;-)
Since some content requests cannot be right, I would set the HTTP status
code to e.g. 404.
Doing this, Apache correctly prints custom headers, application's HTML
content, and then (thus just after </html>) new headers and HTML for
Apache's standard 404 error page.

If someone have any idea on how prevent the second 404 page to be
displayed, I would appreciate this information !

Kind regards,

Bernard.


here is how my app sends datas :
sub print_response {
    my $self=shift;
    $self->{hhttpd}->status_line($self->{status}.'
'.$self->{statustxt});
    foreach (@{$self->{cookies}}) {
        $self->{hhttpd}->header_out->add( "Set-Cookie" => $_ );
    }
    $self->{hhttpd}->content_encoding($self->{encoding});
    $self->{hhttpd}->send_http_header($self->{content_type});
    $self->{hhttpd}->print($self->{content});
    1;
}

note:
my mod_perl 1.27 is built into Apache 1.3.27, under RH7.2





Re: [QUESTION] - Strange Apache error handling

Posted by Bernard Nauwelaerts <bp...@it-development.be>.
Le mar 20/05/2003 à 10:20, Stas Bekman a écrit :
> Bernard Nauwelaerts wrote:
> 
> >> What's not clear is the return value of the handler. 
> >>Most likely you shouldn't mess with the status line yourself, but return the 
> >>HTTP_NOT_FOUND constant if you are using handlers, or set $r->status(404) if 
> >>using a registry script. If you are already taking care of setting the status, 
> >>you should probably return Apache::OK, so the default handler won't be run.
> > 
> > You're right, thanks ! Handler must return OK, otherwise the Apache's
> > 404 is appended to printed results. But Apache logs these requests as
> > 200.
> 
> See above: $r->status(404)

Okay, now it seems to work ! Thanks

Best regards,
--
Bernard


Re: [QUESTION] - Strange Apache error handling

Posted by Stas Bekman <st...@stason.org>.
Bernard Nauwelaerts wrote:

>> What's not clear is the return value of the handler. 
>>Most likely you shouldn't mess with the status line yourself, but return the 
>>HTTP_NOT_FOUND constant if you are using handlers, or set $r->status(404) if 
>>using a registry script. If you are already taking care of setting the status, 
>>you should probably return Apache::OK, so the default handler won't be run.
> 
> You're right, thanks ! Handler must return OK, otherwise the Apache's
> 404 is appended to printed results. But Apache logs these requests as
> 200.

See above: $r->status(404)

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: [QUESTION] - Strange Apache error handling

Posted by Bernard Nauwelaerts <bp...@it-development.be>.
Hi Stas, Ged !

Thanks for your response.

Le lun 19/05/2003 à 03:24, Stas Bekman a écrit : 
> it's not clear how print_response() is called. Is it running under a registry 
>   or mod_perl handler?
handler, right !

>  What's not clear is the return value of the handler. 
> Most likely you shouldn't mess with the status line yourself, but return the 
> HTTP_NOT_FOUND constant if you are using handlers, or set $r->status(404) if 
> using a registry script. If you are already taking care of setting the status, 
> you should probably return Apache::OK, so the default handler won't be run.
You're right, thanks ! Handler must return OK, otherwise the Apache's
404 is appended to printed results. But Apache logs these requests as
200.

Le lun 19/05/2003 à 02:36, Ged Haywood a écrit : 
> You might be better off if you were to do something in the httpd.conf
> with a custom error response, instead of treating a bad request as if
> it were a good one which generated output from your content handler.
Yes, yes, I known. But doing this, I'll loose a lot of features
regarding the context of error.


Best regards,

--
Bernard


Re: [QUESTION] - Strange Apache error handling

Posted by Stas Bekman <st...@stason.org>.
Bernard Nauwelaerts wrote:
> Hi all !
> 
> I'm building a dynamic website using mod_perl ;-)
> Since some content requests cannot be right, I would set the HTTP status
> code to e.g. 404.
> Doing this, Apache correctly prints custom headers, application's HTML
> content, and then (thus just after </html>) new headers and HTML for
> Apache's standard 404 error page.
> 
> If someone have any idea on how prevent the second 404 page to be
> displayed, I would appreciate this information !
> 
> Kind regards,
> 
> Bernard.
> 
> 
> here is how my app sends datas :
> sub print_response {
>     my $self=shift;
>     $self->{hhttpd}->status_line($self->{status}.'
> '.$self->{statustxt});
>     foreach (@{$self->{cookies}}) {
>         $self->{hhttpd}->header_out->add( "Set-Cookie" => $_ );
>     }
>     $self->{hhttpd}->content_encoding($self->{encoding});
>     $self->{hhttpd}->send_http_header($self->{content_type});
>     $self->{hhttpd}->print($self->{content});
>     1;
> }
> 
> note:
> my mod_perl 1.27 is built into Apache 1.3.27, under RH7.2

it's not clear how print_response() is called. Is it running under a registry 
  or mod_perl handler? What's not clear is the return value of the handler. 
Most likely you shouldn't mess with the status line yourself, but return the 
HTTP_NOT_FOUND constant if you are using handlers, or set $r->status(404) if 
using a registry script. If you are already taking care of setting the status, 
you should probably return Apache::OK, so the default handler won't be run.



__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: [QUESTION] - Strange Apache error handling

Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi there,

On 17 May 2003, Bernard Nauwelaerts wrote:

> I'm building a dynamic website using mod_perl ;-)

That's what it's for.  :)

> Since some content requests cannot be right, I would set the HTTP status
> code to e.g. 404.

You might be better off if you were to do something in the httpd.conf
with a custom error response, instead of treating a bad request as if
it were a good one which generated output from your content handler.

73,
Ged.