You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Holger Moser <ho...@artofdefence.com> on 2007/08/27 16:05:09 UTC

Howto return apache status (error) page from ouptut filter ?

Hi,

To keep a long storry short: i have an apache module that sets an
ouput-filter (besides other things), does validate/mangle the data. so
far so good. my question now is how can i get apache to generate an
errorpage by itself if my module wants it to return with e.g. 404
errcode (just returning the status code as outputfilter returnvalue
doesnt work.. i tried that because someone mentioned it could work).
currently i generate my own errorpage with the statuscode as workaround
(but this is only a temp solution). so whats the correct way doing that?


Re: Howto return apache status (error) page from ouptut filter ?

Posted by Joe Lewis <jo...@joe-lewis.com>.
Holger Moser wrote:
> Hi,
>
> To keep a long storry short: i have an apache module that sets an
> ouput-filter (besides other things), does validate/mangle the data. so
> far so good. my question now is how can i get apache to generate an
> errorpage by itself if my module wants it to return with e.g. 404
> errcode (just returning the status code as outputfilter returnvalue
> doesnt work.. i tried that because someone mentioned it could work).
>   

It does, but only in content generators.  You are working in a content
filter, which occurs after any content-generator should have run
(including the error generator itself).  I expect that your only
solution is to generate your own error page, however, I am not any kind
of an expert in this niche you are asking about.

> currently i generate my own errorpage with the statuscode as workaround
> (but this is only a temp solution). so whats the correct way doing that?
>
>   

It should be done using the content generator.  If an output filter runs
and fails, the user really shouldn't end up with an entire 404.  That
should only really occur if the actual document wasn't found.  But
again, that is my opinion.  Take it for what it is worth.

Joe
-- 
Joseph Lewis <http://sharktooth.org/>
"Divide the fire, and you will sooner put it out." - Publius Syrus

Re: Howto return apache status (error) page from output filter ?

Posted by Christopher Vitale <cv...@us.ibm.com>.
Hello,

I've got some questions about Nick's comments on filters and errors. I
understand why setting an error status on an output filter is dicey. What
about content input filters?

Are handlers required to detect errors in inbound filters, pass them to
Apache,  and respect r->status?
Is this more of a best practice that some people choose not to follow?
Are handlers encouraged to decide for themselves what is correct as
handlers can be so varied?

When I first started looking at filters I thought that the handlers would
respect inbound filter errors, stop processing, and hand an error code to
Apache. If mod_deflate is given a compressed upload and detects an error
then the entire request should be considered to be as dangerous as
radioactive waste. Throwing away the bad buckets and proceeding with the
request shouldn't be an option.

In practice, I'm starting to think that handlers do whatever they wish.
This makes things messy because handlers lack uniformity. A hacked upload
would return a 400 error with handler X and a 200  with handler Y.

Are there hard and fast rules for real world handlers?

vitale



                                                                                                                                  
  From:       Nick Kew <ni...@webthing.com>                                                                                        
                                                                                                                                  
  To:         modules-dev@httpd.apache.org                                                                                        
                                                                                                                                  
  Date:       08/27/2007 11:37 AM                                                                                                 
                                                                                                                                  
  Subject:    Re: Howto return apache status (error) page from ouptut filter ?                                                    
                                                                                                                                  





On Mon, 27 Aug 2007 16:05:09 +0200
Holger Moser <ho...@artofdefence.com> wrote:

> Hi,
>
> To keep a long storry short: i have an apache module that sets an
> ouput-filter (besides other things), does validate/mangle the data. so
> far so good. my question now is how can i get apache to generate an
> errorpage by itself if my module wants it to return with e.g. 404
> errcode (just returning the status code as outputfilter returnvalue
> doesnt work.. i tried that because someone mentioned it could work).
> currently i generate my own errorpage with the statuscode as
> workaround (but this is only a temp solution). so whats the correct
> way doing that?

A filter is the wrong place to set an error status.  Your filter
function is a callback, and in general will be called after the
response status has already been sent to the client.

The exception to that is in the first call to your filter function.
But if you're relying on that, it points to a problem in your
design.  Though in that case, you can still set r->status and
return APR_EGENERAL, and hope the content generator (which is
in control) does what you want.

--
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/

Re: Howto return apache status (error) page from ouptut filter ?

Posted by Nick Kew <ni...@webthing.com>.
On Mon, 27 Aug 2007 16:05:09 +0200
Holger Moser <ho...@artofdefence.com> wrote:

> Hi,
> 
> To keep a long storry short: i have an apache module that sets an
> ouput-filter (besides other things), does validate/mangle the data. so
> far so good. my question now is how can i get apache to generate an
> errorpage by itself if my module wants it to return with e.g. 404
> errcode (just returning the status code as outputfilter returnvalue
> doesnt work.. i tried that because someone mentioned it could work).
> currently i generate my own errorpage with the statuscode as
> workaround (but this is only a temp solution). so whats the correct
> way doing that?

A filter is the wrong place to set an error status.  Your filter
function is a callback, and in general will be called after the
response status has already been sent to the client.

The exception to that is in the first call to your filter function.
But if you're relying on that, it points to a problem in your
design.  Though in that case, you can still set r->status and
return APR_EGENERAL, and hope the content generator (which is
in control) does what you want.

-- 
Nick Kew

Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/