[PATCH] Ignore unexpected 1xx status messages from the upstream.
Piotr Sikora
piotr at cloudflare.com
Fri Dec 21 04:13:04 UTC 2012
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;
+ }
}
break;
@@ -1600,6 +1613,58 @@
default:
return NGX_ERROR;
}
+ break;
+
+ /* space or end of line in ignored part */
+ case sw_ignore_space_after_status:
+ switch (ch) {
+ case ' ':
+ state = sw_ignore_text;
+ break;
+ case CR:
+ state = sw_ignore_text;
+ break;
+ case LF:
+ state = sw_ignore_start;
+ break;
+ default:
+ return NGX_ERROR;
+ }
+ break;
+
+ /* new line in ignored part */
+ case sw_ignore_start:
+ switch (ch) {
+ case CR:
+ state = sw_ignore_almost_done;
+ break;
+ case LF:
+ state = sw_start;
+ break;
+ default:
+ state = sw_ignore_text;
+ break;
+ }
+ break;
+
+ /* any text in ignored part until end of line */
+ case sw_ignore_text:
+ switch (ch) {
+ case LF:
+ state = sw_ignore_start;
+ break;
+ }
+ break;
+
+ /* end of ignored part */
+ case sw_ignore_almost_done:
+ switch (ch) {
+ case LF:
+ state = sw_start;
+ break;
+ default:
+ return NGX_ERROR;
+ }
}
}
--
1.8.0.2
More information about the nginx-devel
mailing list