Welcome! Log In Create A New Profile

Advanced

HTTP/2 custom status codes

Posted by Sharan J 
Sharan J
HTTP/2 custom status codes
August 09, 2017 05:20PM
Hello,

I am using Nginx as a reverse proxy and have enabled HTTP/2. For a
particular request, my back-end server sends a custom 4 digit status code
(say 9999).

When connecting via HTTP/1.1, the exact status code is returned to the
client but, when connection via HTTP/2, the response headers along with the
status(9999) sent by my back-end server is sent in the body and the header
has the status code 000.

The same works fine if the custom status code is 3-digit (say 999). I know
the standard is to use 3 digit status code but, why does Nginx sends the
back-end server's response headers in the body? Please help me understand
what exactly is happening.

Thanks,
Shanthu
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: HTTP/2 custom status codes
August 09, 2017 05:40PM
Hello!

On Wed, Aug 09, 2017 at 08:46:41PM +0530, Sharan J wrote:

> Hello,
>
> I am using Nginx as a reverse proxy and have enabled HTTP/2. For a
> particular request, my back-end server sends a custom 4 digit status code
> (say 9999).
>
> When connecting via HTTP/1.1, the exact status code is returned to the
> client but, when connection via HTTP/2, the response headers along with the
> status(9999) sent by my back-end server is sent in the body and the header
> has the status code 000.
>
> The same works fine if the custom status code is 3-digit (say 999). I know
> the standard is to use 3 digit status code but, why does Nginx sends the
> back-end server's response headers in the body? Please help me understand
> what exactly is happening.

When you return a 4-digit status code from your backend, nginx
will fail to parse the HTTP response of the backend, and will
assume that backend is using HTTP/0.9. Something like this will
be logged to the error log:

.... [error] ... upstream sent no valid HTTP/1.0 header while reading response header from upstream ...

Since there are no headers in HTTP/0.9, everything returned by
the backend will be considered to be a response body.

--
Maxim Dounin
http://nginx.org/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sharan J
Re: HTTP/2 custom status codes
August 09, 2017 06:30PM
Hi,

Thanks for the response.

> ... [error] ... upstream sent no valid HTTP/1.0 header while reading
response header from upstream ...

This is logged in the error log for both HTTP/1.1 and HTTP/2. May I know
why everything returned by the backend is considered as the response body
in HTTP/2 alone? and not in HTTP/1.1?

Thanks,
Shanthu

On Wed, Aug 9, 2017 at 9:07 PM, Maxim Dounin <[email protected]> wrote:

> Hello!
>
> On Wed, Aug 09, 2017 at 08:46:41PM +0530, Sharan J wrote:
>
> > Hello,
> >
> > I am using Nginx as a reverse proxy and have enabled HTTP/2. For a
> > particular request, my back-end server sends a custom 4 digit status code
> > (say 9999).
> >
> > When connecting via HTTP/1.1, the exact status code is returned to the
> > client but, when connection via HTTP/2, the response headers along with
> the
> > status(9999) sent by my back-end server is sent in the body and the
> header
> > has the status code 000.
> >
> > The same works fine if the custom status code is 3-digit (say 999). I
> know
> > the standard is to use 3 digit status code but, why does Nginx sends the
> > back-end server's response headers in the body? Please help me understand
> > what exactly is happening.
>
> When you return a 4-digit status code from your backend, nginx
> will fail to parse the HTTP response of the backend, and will
> assume that backend is using HTTP/0.9. Something like this will
> be logged to the error log:
>
> ... [error] ... upstream sent no valid HTTP/1.0 header while reading
> response header from upstream ...
>
> Since there are no headers in HTTP/0.9, everything returned by
> the backend will be considered to be a response body.
>
> --
> Maxim Dounin
> http://nginx.org/
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Maxim Dounin
Re: HTTP/2 custom status codes
August 09, 2017 07:30PM
Hello!

On Wed, Aug 09, 2017 at 09:56:26PM +0530, Sharan J wrote:

> Thanks for the response.
>
> > ... [error] ... upstream sent no valid HTTP/1.0 header while reading
> response header from upstream ...
>
> This is logged in the error log for both HTTP/1.1 and HTTP/2. May I know
> why everything returned by the backend is considered as the response body
> in HTTP/2 alone? and not in HTTP/1.1?

It is considered to be the response body in both cases. Though in
case of HTTP/1.x nginx downgrades client's connection to HTTP/0.9
as well, and returns the HTTP/0.9 response as it was got from the
backend.

--
Maxim Dounin
http://nginx.org/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login