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 John Zhang <jo...@yahoo.com> on 2008/12/09 22:25:09 UTC
How to return an error code/page from output filter?
When I encounter certain error conditions in my output filter, I would like to return a specific error code/page (eg 503 - service not available). However, the following code results in a 500 beeing returned to the browser:
apr_status_t my_out_filter(ap_filter_t *f, apr_bucket_brigade *bb)
{
....
if (I_should_return_503)
{
ap_remove_output_filter(f);
// f->r->status = HTTP_SERVICE_UNAVAILABLE;
return HTTP_SERVICE_UNAVAILABLE;
}
....
}
In fact, no matter what error code I return, the browser always gets a 500 error. Also, if I uncomment the "f->r->..." line, the browser gets an empty (200) page.
Any suggestions?
Thanks in advance,
John
Re: How to return an error code/page from output filter?
Posted by Subra Aswathanarayanan <as...@gmail.com>.
Try this:
apr_status_t my_out_filter(ap_filter_t *f, apr_bucket_brigade *bb)
{
....
if (I_should_return_503)
{
ap_remove_output_filter(f);
f->r->status = HTTP_SERVICE_UNAVAILABLE;
return HTTP_OK;
}
....
}
On Tue, Dec 9, 2008 at 4:25 PM, John Zhang <jo...@yahoo.com> wrote:
> When I encounter certain error conditions in my output filter, I would like
> to return a specific error code/page (eg 503 - service not available).
> However, the following code results in a 500 beeing returned to the
> browser:
>
> apr_status_t my_out_filter(ap_filter_t *f, apr_bucket_brigade *bb)
> {
> ....
> if (I_should_return_503)
> {
> ap_remove_output_filter(f);
> // f->r->status = HTTP_SERVICE_UNAVAILABLE;
> return HTTP_SERVICE_UNAVAILABLE;
> }
> ....
> }
>
> In fact, no matter what error code I return, the browser always gets a 500
> error. Also, if I uncomment the "f->r->..." line, the browser gets an empty
> (200) page.
>
> Any suggestions?
>
> Thanks in advance,
> John
>
>