diff --git a/src/event/ngx_event_pipe.c b/src/event/ngx_event_pipe.c index 7bbca4b24c..c3ac400434 100644 --- a/src/event/ngx_event_pipe.c +++ b/src/event/ngx_event_pipe.c @@ -539,6 +539,21 @@ ngx_event_pipe_write_to_downstream(ngx_event_pipe_t *p) if (p->upstream_eof || p->upstream_error || p->upstream_done) { + /* the first free buf is partially filled */ + + if (p->upstream_error + && p->free_raw_bufs + && p->free_raw_bufs->buf->pos != p->free_raw_bufs->buf->last) + { + /* STUB */ p->free_raw_bufs->buf->num = p->num++; + + if (p->input_filter(p, p->free_raw_bufs->buf) == NGX_ERROR) { + return NGX_ABORT; + } + + p->free_raw_bufs = p->free_raw_bufs->next; + } + /* pass the p->out and p->in chains to the output filter */ for (cl = p->busy; cl; cl = cl->next) { diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c index 3f865345ba..918aa239cf 100644 --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -4369,6 +4369,19 @@ ngx_http_upstream_process_upstream(ngx_http_request_t *r, p->upstream_error = 1; ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out"); + /* + * flush data already read from the upstream, except for + * an unrequested 101 response, whose body is not part + * of the response + */ + + if (u->headers_in.status_n != NGX_HTTP_SWITCHING_PROTOCOLS + && ngx_event_pipe(p, 1) == NGX_ABORT) + { + ngx_http_upstream_finalize_request(r, u, NGX_ERROR); + return; + } + } else { if (rev->delayed) {