diff options
author | Maxim Dounin <mdounin@mdounin.ru> | 2013-02-01 14:41:50 +0000 |
---|---|---|
committer | Maxim Dounin <mdounin@mdounin.ru> | 2013-02-01 14:41:50 +0000 |
commit | aad0a1dba6e05766005a60b893c53e52fb056795 (patch) | |
tree | d4f6649233d5c1487f3e59cf558114802a6cd9af | |
parent | e8efec0e5e154fc21ba3d1d8b08a94c2eba6e757 (diff) | |
download | nginx-aad0a1dba6e05766005a60b893c53e52fb056795.tar.gz nginx-aad0a1dba6e05766005a60b893c53e52fb056795.zip |
FastCGI: proper handling of split fastcgi end request.
If fastcgi end request record was split between several network packets,
with fastcgi_keep_conn it was possible that connection was saved in incorrect
state (e.g. with padding bytes not yet read).
-rw-r--r-- | src/http/modules/ngx_http_fastcgi_module.c | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/src/http/modules/ngx_http_fastcgi_module.c b/src/http/modules/ngx_http_fastcgi_module.c index 6134c92d3..f386926da 100644 --- a/src/http/modules/ngx_http_fastcgi_module.c +++ b/src/http/modules/ngx_http_fastcgi_module.c @@ -1701,17 +1701,15 @@ ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf) } if (f->type == NGX_HTTP_FASTCGI_END_REQUEST) { - f->state = ngx_http_fastcgi_st_padding; - - p->upstream_done = 1; - - if (flcf->keep_conn) { - r->upstream->keepalive = 1; - } ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0, "http fastcgi sent end request"); + if (!flcf->keep_conn) { + p->upstream_done = 1; + break; + } + continue; } } @@ -1719,6 +1717,24 @@ ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf) if (f->state == ngx_http_fastcgi_st_padding) { + if (f->type == NGX_HTTP_FASTCGI_END_REQUEST) { + + if (f->pos + f->padding < f->last) { + p->upstream_done = 1; + break; + } + + if (f->pos + f->padding == f->last) { + p->upstream_done = 1; + r->upstream->keepalive = 1; + break; + } + + f->padding -= f->last - f->pos; + + break; + } + if (f->pos + f->padding < f->last) { f->state = ngx_http_fastcgi_st_version; f->pos += f->padding; @@ -1777,6 +1793,20 @@ ngx_http_fastcgi_input_filter(ngx_event_pipe_t *p, ngx_buf_t *buf) continue; } + if (f->type == NGX_HTTP_FASTCGI_END_REQUEST) { + + if (f->pos + f->length <= f->last) { + f->state = ngx_http_fastcgi_st_padding; + f->pos += f->length; + + continue; + } + + f->length -= f->last - f->pos; + + break; + } + /* f->type == NGX_HTTP_FASTCGI_STDOUT */ |