error pages: bug or feature?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

error pages: bug or feature?

Piotr Sikora
Hello,
I noticed that config:

server {
    location / {
        // doesn't exist, will result in 502
        proxy_pass    <a href="http://localhost:11111;">http://localhost:11111;
        error_page    502    @fetch;
    }
    location @fetch {
        proxy_pass    <a href="http://localhost:8080;">http://localhost:8080;
    }
}

will result in response from http://localhost:8080 and "502 Bad Gateway"
status,
while config:

server {
    location / {
        // doesn't exist, will result in 502
        proxy_pass    <a href="http://localhost:11111;">http://localhost:11111;
        error_page    502    = @fetch;
    }
    location @fetch {
        proxy_pass    <a href="http://localhost:8080;">http://localhost:8080;
    }
}

will result in response from http://localhost:8080 and "200 OK" status.

The cause of this difference is '=' sign and the fact that
ngx_http_core_error_page function sets overwrite to -1 in first case, and
overwrite to 0 in second case.

Is passing original response status with headers and body from "error page"
some kind of feature or is it a bug and error pages without '=' shouldn't be
allowed at all?

Best regards,
Piotr Sikora < [hidden email] >


Reply | Threaded
Open this post in threaded view
|

Re: error pages: bug or feature?

Igor Sysoev
On Sun, Jul 19, 2009 at 02:28:25AM +0200, Piotr Sikora wrote:

> Hello,
> I noticed that config:
>
> server {
>    location / {
>        // doesn't exist, will result in 502
>        proxy_pass    <a href="http://localhost:11111;">http://localhost:11111;
>        error_page    502    @fetch;
>    }
>    location @fetch {
>        proxy_pass    <a href="http://localhost:8080;">http://localhost:8080;
>    }
> }
>
> will result in response from http://localhost:8080 and "502 Bad Gateway"
> status,
> while config:
>
> server {
>    location / {
>        // doesn't exist, will result in 502
>        proxy_pass    <a href="http://localhost:11111;">http://localhost:11111;
>        error_page    502    = @fetch;
>    }
>    location @fetch {
>        proxy_pass    <a href="http://localhost:8080;">http://localhost:8080;
>    }
> }
>
> will result in response from http://localhost:8080 and "200 OK" status.
>
> The cause of this difference is '=' sign and the fact that
> ngx_http_core_error_page function sets overwrite to -1 in first case, and
> overwrite to 0 in second case.
>
> Is passing original response status with headers and body from "error page"
> some kind of feature or is it a bug and error pages without '=' shouldn't
> be allowed at all?

This is not a bug and not a feature (if you mean a feature as "well known
and documentated bug"). This is intended behaviour:

http://wiki.nginx.org/NginxHttpCoreModule#error_page

Otherwise, you will not be able to show your custom static error_page's
with original response status, it would always return 200 response:

    error_page  404  /404.html;

    location = /404.html {
        root  /path/to/page;
    }


--
Igor Sysoev
http://sysoev.ru/en/

Reply | Threaded
Open this post in threaded view
|

Re: error pages: bug or feature?

Piotr Sikora
> This is not a bug and not a feature (if you mean a feature as "well known
> and documentated bug"). This is intended behaviour:

By feature I meant "intended behaviour" ;)

> http://wiki.nginx.org/NginxHttpCoreModule#error_page
>
> Otherwise, you will not be able to show your custom static error_page's
> with original response status, it would always return 200 response:
>
>    error_page  404  /404.html;
>
>    location = /404.html {
>        root  /path/to/page;
>    }

Of course, you're right. Next time I'll read documentation first, instead of
trying to find not existing bugs in the code... Sorry for the noise!

Best regards,
Piotr Sikora < [hidden email] >