Mercurial > hg > nginx
comparison src/http/modules/ngx_http_proxy_module.c @ 7675:9afa45068b8f
Proxy: drop extra data sent by upstream.
Previous behaviour was to pass everything to the client, but this
seems to be suboptimal and causes issues (ticket #1695). Fix is to
drop extra data instead, as it naturally happens in most clients.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 06 Jul 2020 18:36:19 +0300 |
parents | 8981dbb12254 |
children | d225b70d38b6 |
comparison
equal
deleted
inserted
replaced
7674:7731c710796f | 7675:9afa45068b8f |
---|---|
2013 | 2013 |
2014 if (buf->pos == buf->last) { | 2014 if (buf->pos == buf->last) { |
2015 return NGX_OK; | 2015 return NGX_OK; |
2016 } | 2016 } |
2017 | 2017 |
2018 if (p->upstream_done) { | |
2019 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0, | |
2020 "http proxy data after close"); | |
2021 return NGX_OK; | |
2022 } | |
2023 | |
2024 if (p->length == 0) { | |
2025 | |
2026 ngx_log_error(NGX_LOG_WARN, p->log, 0, | |
2027 "upstream sent more data than specified in " | |
2028 "\"Content-Length\" header"); | |
2029 | |
2030 r = p->input_ctx; | |
2031 r->upstream->keepalive = 0; | |
2032 p->upstream_done = 1; | |
2033 | |
2034 return NGX_OK; | |
2035 } | |
2036 | |
2018 cl = ngx_chain_get_free_buf(p->pool, &p->free); | 2037 cl = ngx_chain_get_free_buf(p->pool, &p->free); |
2019 if (cl == NULL) { | 2038 if (cl == NULL) { |
2020 return NGX_ERROR; | 2039 return NGX_ERROR; |
2021 } | 2040 } |
2022 | 2041 |
2040 | 2059 |
2041 if (p->length == -1) { | 2060 if (p->length == -1) { |
2042 return NGX_OK; | 2061 return NGX_OK; |
2043 } | 2062 } |
2044 | 2063 |
2064 if (b->last - b->pos > p->length) { | |
2065 | |
2066 ngx_log_error(NGX_LOG_WARN, p->log, 0, | |
2067 "upstream sent more data than specified in " | |
2068 "\"Content-Length\" header"); | |
2069 | |
2070 b->last = b->pos + p->length; | |
2071 p->upstream_done = 1; | |
2072 | |
2073 return NGX_OK; | |
2074 } | |
2075 | |
2045 p->length -= b->last - b->pos; | 2076 p->length -= b->last - b->pos; |
2046 | 2077 |
2047 if (p->length == 0) { | 2078 if (p->length == 0) { |
2048 r = p->input_ctx; | 2079 r = p->input_ctx; |
2049 p->upstream_done = 1; | |
2050 r->upstream->keepalive = !r->upstream->headers_in.connection_close; | 2080 r->upstream->keepalive = !r->upstream->headers_in.connection_close; |
2051 | |
2052 } else if (p->length < 0) { | |
2053 r = p->input_ctx; | |
2054 p->upstream_done = 1; | |
2055 | |
2056 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, | |
2057 "upstream sent more data than specified in " | |
2058 "\"Content-Length\" header"); | |
2059 } | 2081 } |
2060 | 2082 |
2061 return NGX_OK; | 2083 return NGX_OK; |
2062 } | 2084 } |
2063 | 2085 |
2222 b->last += bytes; | 2244 b->last += bytes; |
2223 cl->buf->last = b->last; | 2245 cl->buf->last = b->last; |
2224 cl->buf->tag = u->output.tag; | 2246 cl->buf->tag = u->output.tag; |
2225 | 2247 |
2226 if (u->length == -1) { | 2248 if (u->length == -1) { |
2249 return NGX_OK; | |
2250 } | |
2251 | |
2252 if (bytes > u->length) { | |
2253 | |
2254 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0, | |
2255 "upstream sent more data than specified in " | |
2256 "\"Content-Length\" header"); | |
2257 | |
2258 cl->buf->last = cl->buf->pos + u->length; | |
2259 u->length = 0; | |
2260 | |
2227 return NGX_OK; | 2261 return NGX_OK; |
2228 } | 2262 } |
2229 | 2263 |
2230 u->length -= bytes; | 2264 u->length -= bytes; |
2231 | 2265 |