mirror of https://github.com/openresty/openresty
renamed the "nonbuffered-upstream-truncation" patch to "upstream-truncation" patch; also fixed issues with chunked upstream response bodies. thanks Andy Yuan for reporting this issue in #24.
parent
1d909539a8
commit
042e2fd27b
@ -1,63 +0,0 @@
|
||||
--- nginx-1.2.7/src/http/ngx_http_upstream.c 2012-08-06 10:34:08.000000000 -0700
|
||||
+++ nginx-1.2.7-patched/src/http/ngx_http_upstream.c 2012-09-09 21:58:04.727761891 -0700
|
||||
@@ -2383,7 +2383,7 @@
|
||||
|
||||
if (c->read->timedout) {
|
||||
ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");
|
||||
- ngx_http_upstream_finalize_request(r, u, 0);
|
||||
+ ngx_http_upstream_finalize_request(r, u, NGX_HTTP_GATEWAY_TIME_OUT);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2430,13 +2430,17 @@
|
||||
if (u->busy_bufs == NULL) {
|
||||
|
||||
if (u->length == 0
|
||||
- || upstream->read->eof
|
||||
- || upstream->read->error)
|
||||
+ || (upstream->read->eof && u->headers_in.content_length_n == -1))
|
||||
{
|
||||
ngx_http_upstream_finalize_request(r, u, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
+ if (upstream->read->eof || upstream->read->error) {
|
||||
+ ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
b->pos = b->start;
|
||||
b->last = b->start;
|
||||
}
|
||||
@@ -2710,7 +2714,16 @@
|
||||
#if 0
|
||||
ngx_http_busy_unlock(u->conf->busy_lock, &u->busy_lock);
|
||||
#endif
|
||||
- ngx_http_upstream_finalize_request(r, u, 0);
|
||||
+
|
||||
+ if (p->upstream_done
|
||||
+ || (p->upstream_eof && u->headers_in.content_length_n == -1))
|
||||
+ {
|
||||
+ ngx_http_upstream_finalize_request(r, u, 0);
|
||||
+
|
||||
+ } else {
|
||||
+ ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);
|
||||
+ }
|
||||
+
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -3073,6 +3086,13 @@
|
||||
&& rc != NGX_HTTP_REQUEST_TIME_OUT
|
||||
&& (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE))
|
||||
{
|
||||
+ if (rc == NGX_ERROR) {
|
||||
+ r->headers_out.status = NGX_HTTP_INTERNAL_SERVER_ERROR;
|
||||
+
|
||||
+ } else {
|
||||
+ r->headers_out.status = rc;
|
||||
+ }
|
||||
+
|
||||
rc = 0;
|
||||
}
|
||||
|
@ -0,0 +1,83 @@
|
||||
--- nginx-1.2.7/src/http/ngx_http_upstream.c 2013-02-11 06:39:49.000000000 -0800
|
||||
+++ nginx-1.2.7-patched/src/http/ngx_http_upstream.c 2013-04-04 18:18:09.749357094 -0700
|
||||
@@ -2399,7 +2399,7 @@ ngx_http_upstream_process_non_buffered_u
|
||||
|
||||
if (c->read->timedout) {
|
||||
ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");
|
||||
- ngx_http_upstream_finalize_request(r, u, 0);
|
||||
+ ngx_http_upstream_finalize_request(r, u, NGX_HTTP_GATEWAY_TIME_OUT);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2415,11 +2415,13 @@ ngx_http_upstream_process_non_buffered_r
|
||||
ssize_t n;
|
||||
ngx_buf_t *b;
|
||||
ngx_int_t rc;
|
||||
+ ngx_event_pipe_t *p;
|
||||
ngx_connection_t *downstream, *upstream;
|
||||
ngx_http_upstream_t *u;
|
||||
ngx_http_core_loc_conf_t *clcf;
|
||||
|
||||
u = r->upstream;
|
||||
+ p = u->pipe;
|
||||
downstream = r->connection;
|
||||
upstream = u->peer.connection;
|
||||
|
||||
@@ -2446,13 +2448,19 @@ ngx_http_upstream_process_non_buffered_r
|
||||
if (u->busy_bufs == NULL) {
|
||||
|
||||
if (u->length == 0
|
||||
- || upstream->read->eof
|
||||
- || upstream->read->error)
|
||||
+ || (upstream->read->eof
|
||||
+ && u->length == -1
|
||||
+ && p->length == -1))
|
||||
{
|
||||
ngx_http_upstream_finalize_request(r, u, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
+ if (upstream->read->eof || upstream->read->error) {
|
||||
+ ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
b->pos = b->start;
|
||||
b->last = b->start;
|
||||
}
|
||||
@@ -2720,7 +2728,9 @@ ngx_http_upstream_process_request(ngx_ht
|
||||
|
||||
#endif
|
||||
|
||||
- if (p->upstream_done || p->upstream_eof || p->upstream_error) {
|
||||
+ if (p->upstream_done
|
||||
+ || (p->upstream_eof && u->length == -1 && p->length == -1))
|
||||
+ {
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
"http upstream exit: %p", p->out);
|
||||
#if 0
|
||||
@@ -2729,6 +2739,14 @@ ngx_http_upstream_process_request(ngx_ht
|
||||
ngx_http_upstream_finalize_request(r, u, 0);
|
||||
return;
|
||||
}
|
||||
+
|
||||
+ if (p->upstream_eof || p->upstream_error) {
|
||||
+ ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
|
||||
+ "http upstream exit: %p", p->out);
|
||||
+
|
||||
+ ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
|
||||
+ return;
|
||||
+ }
|
||||
}
|
||||
|
||||
if (p->downstream_error) {
|
||||
@@ -3087,7 +3105,8 @@ ngx_http_upstream_finalize_request(ngx_h
|
||||
|
||||
if (u->header_sent
|
||||
&& rc != NGX_HTTP_REQUEST_TIME_OUT
|
||||
- && (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE))
|
||||
+ && rc != NGX_HTTP_GATEWAY_TIME_OUT
|
||||
+ && rc >= NGX_HTTP_SPECIAL_RESPONSE)
|
||||
{
|
||||
rc = 0;
|
||||
}
|
Loading…
Reference in New Issue