comparison src/http/ngx_http_upstream.c @ 5301:a50e26148d21

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.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 25 Jul 2013 15:00:12 +0400
parents f538a67c9f77
children 292c92fb05d7
comparison
equal deleted inserted replaced
5300:f538a67c9f77 5301:a50e26148d21
2746 } 2746 }
2747 2747
2748 if (u->busy_bufs == NULL) { 2748 if (u->busy_bufs == NULL) {
2749 2749
2750 if (u->length == 0 2750 if (u->length == 0
2751 || upstream->read->eof 2751 || (upstream->read->eof && u->length == -1))
2752 || upstream->read->error)
2753 { 2752 {
2754 ngx_http_upstream_finalize_request(r, u, 0); 2753 ngx_http_upstream_finalize_request(r, u, 0);
2754 return;
2755 }
2756
2757 if (upstream->read->eof) {
2758 ngx_log_error(NGX_LOG_ERR, upstream->log, 0,
2759 "upstream prematurely closed connection");
2760
2761 ngx_http_upstream_finalize_request(r, u,
2762 NGX_HTTP_BAD_GATEWAY);
2763 return;
2764 }
2765
2766 if (upstream->read->error) {
2767 ngx_http_upstream_finalize_request(r, u,
2768 NGX_HTTP_BAD_GATEWAY);
2755 return; 2769 return;
2756 } 2770 }
2757 2771
2758 b->pos = b->start; 2772 b->pos = b->start;
2759 b->last = b->start; 2773 b->last = b->start;
3025 #endif 3039 #endif
3026 3040
3027 if (p->upstream_done || p->upstream_eof || p->upstream_error) { 3041 if (p->upstream_done || p->upstream_eof || p->upstream_error) {
3028 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 3042 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
3029 "http upstream exit: %p", p->out); 3043 "http upstream exit: %p", p->out);
3030 ngx_http_upstream_finalize_request(r, u, 0); 3044
3045 if (p->upstream_done
3046 || (p->upstream_eof && p->length == -1))
3047 {
3048 ngx_http_upstream_finalize_request(r, u, 0);
3049 return;
3050 }
3051
3052 if (p->upstream_eof) {
3053 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
3054 "upstream prematurely closed connection");
3055 }
3056
3057 ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);
3031 return; 3058 return;
3032 } 3059 }
3033 } 3060 }
3034 3061
3035 if (p->downstream_error) { 3062 if (p->downstream_error) {