[PATCH] Ignore unexpected 1xx status messages from the upstream.

Maxim Dounin mdounin at mdounin.ru
Fri Dec 21 14:46:44 UTC 2012


Hello!

On Thu, Dec 20, 2012 at 08:13:04PM -0800, Piotr Sikora wrote:

> Ignore unexpected 1xx status messages from the upstream.
> 
> RFC2616 10.1 Informational 1xx says:
> A client MUST be prepared to accept one or more 1xx status responses
> prior to a regular response, even if the client does not expect a 100
> (Continue) status message. Unexpected 1xx status responses MAY be
> ignored by a user agent.
> 
> Signed-off-by: Piotr Sikora <piotr at cloudflare.com>
> ---
>  src/http/ngx_http_parse.c | 71 +++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 68 insertions(+), 3 deletions(-)
> 
> diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
> index a6ee74e..835edda 100644
> --- a/src/http/ngx_http_parse.c
> +++ b/src/http/ngx_http_parse.c
> @@ -1432,7 +1432,11 @@
>          sw_status,
>          sw_space_after_status,
>          sw_status_text,
> -        sw_almost_done
> +        sw_almost_done,
> +        sw_ignore_space_after_status,
> +        sw_ignore_start,
> +        sw_ignore_text,
> +        sw_ignore_almost_done
>      } state;
> 
>      state = r->state;
> @@ -1554,8 +1558,17 @@
>              status->code = status->code * 10 + ch - '0';
> 
>              if (++status->count == 3) {
> -                state = sw_space_after_status;
> -                status->start = p - 2;
> +                if (status->code == 100
> +                    && r->http_major == 1 && r->http_minor == 1)
> +                {
> +                    state = sw_ignore_space_after_status;
> +                    status->code = 0;
> +                    status->count = 0;
> +
> +                } else {
> +                    state = sw_space_after_status;
> +                    status->start = p - 2;
> +                }

I don't like this to be done this way.  It's protocol module (== 
proxy) which should decide what to do based on a response code, 
not a parser.  And, BTW, another valid 1xx code which upstream 
servers may send unexpectedly seems to be 102 Processing.

Additionally, proper handling of 101 will be required for upcoming 
websockets support.

-- 
Maxim Dounin
http://nginx.com/support.html



More information about the nginx-devel mailing list