Klaus Demo nginx / 960d0bf
Upstream: added check if a response is complete. Checks were added to both buffered and unbuffered code paths to detect and complain if a response is incomplete. Appropriate error codes are now passed to ngx_http_upstream_finalize_request(). With this change in unbuffered mode we now use u->length set to -1 as an indicator that EOF is allowed per protocol and used to indicate response end (much like its with p->length in buffered mode). Proxy module was changed to set u->length to 1 (instead of previously used -1) in case of chunked transfer encoding used to comply with the above. Maxim Dounin 8 years ago
2 changed file(s) with 31 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
15411541 u->pipe->length = 3; /* "0" LF LF */
15421542
15431543 u->input_filter = ngx_http_proxy_non_buffered_chunked_filter;
1544 u->length = -1;
1544 u->length = 1;
15451545
15461546 } else if (u->headers_in.content_length_n == 0) {
15471547 /* empty body: special case as filter won't be called */
27472747 if (u->busy_bufs == NULL) {
27482748
27492749 if (u->length == 0
2750 || upstream->read->eof
2751 || upstream->read->error)
2750 || (upstream->read->eof && u->length == -1))
27522751 {
27532752 ngx_http_upstream_finalize_request(r, u, 0);
2753 return;
2754 }
2755
2756 if (upstream->read->eof) {
2757 ngx_log_error(NGX_LOG_ERR, upstream->log, 0,
2758 "upstream prematurely closed connection");
2759
2760 ngx_http_upstream_finalize_request(r, u,
2761 NGX_HTTP_BAD_GATEWAY);
2762 return;
2763 }
2764
2765 if (upstream->read->error) {
2766 ngx_http_upstream_finalize_request(r, u,
2767 NGX_HTTP_BAD_GATEWAY);
27542768 return;
27552769 }
27562770
30263040 if (p->upstream_done || p->upstream_eof || p->upstream_error) {
30273041 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
30283042 "http upstream exit: %p", p->out);
3029 ngx_http_upstream_finalize_request(r, u, 0);
3043
3044 if (p->upstream_done
3045 || (p->upstream_eof && p->length == -1))
3046 {
3047 ngx_http_upstream_finalize_request(r, u, 0);
3048 return;
3049 }
3050
3051 if (p->upstream_eof) {
3052 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
3053 "upstream prematurely closed connection");
3054 }
3055
3056 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);
30303057 return;
30313058 }
30323059 }