comparison src/http/modules/ngx_http_proxy_module.c @ 7676:d225b70d38b6

Proxy: detection of data after final chunk. Previously, additional data after final chunk was either ignored (in the same buffer, or during unbuffered proxying) or sent to the client (in the next buffer already if it was already read from the socket). Now additional data are properly detected and ignored in all cases. Additionally, a warning is now logged and keepalive is disabled in the connection.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 06 Jul 2020 18:36:20 +0300
parents 9afa45068b8f
children a786e491d08d
comparison
equal deleted inserted replaced
7675:9afa45068b8f 7676:d225b70d38b6
2102 2102
2103 if (ctx == NULL) { 2103 if (ctx == NULL) {
2104 return NGX_ERROR; 2104 return NGX_ERROR;
2105 } 2105 }
2106 2106
2107 if (p->upstream_done) {
2108 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, p->log, 0,
2109 "http proxy data after close");
2110 return NGX_OK;
2111 }
2112
2113 if (p->length == 0) {
2114
2115 ngx_log_error(NGX_LOG_WARN, p->log, 0,
2116 "upstream sent data after final chunk");
2117
2118 r->upstream->keepalive = 0;
2119 p->upstream_done = 1;
2120
2121 return NGX_OK;
2122 }
2123
2107 b = NULL; 2124 b = NULL;
2108 prev = &buf->shadow; 2125 prev = &buf->shadow;
2109 2126
2110 for ( ;; ) { 2127 for ( ;; ) {
2111 2128
2164 2181
2165 if (rc == NGX_DONE) { 2182 if (rc == NGX_DONE) {
2166 2183
2167 /* a whole response has been parsed successfully */ 2184 /* a whole response has been parsed successfully */
2168 2185
2169 p->upstream_done = 1; 2186 p->length = 0;
2170 r->upstream->keepalive = !r->upstream->headers_in.connection_close; 2187 r->upstream->keepalive = !r->upstream->headers_in.connection_close;
2188
2189 if (buf->pos != buf->last) {
2190 ngx_log_error(NGX_LOG_WARN, p->log, 0,
2191 "upstream sent data after final chunk");
2192 r->upstream->keepalive = 0;
2193 }
2171 2194
2172 break; 2195 break;
2173 } 2196 }
2174 2197
2175 if (rc == NGX_AGAIN) { 2198 if (rc == NGX_AGAIN) {
2344 2367
2345 /* a whole response has been parsed successfully */ 2368 /* a whole response has been parsed successfully */
2346 2369
2347 u->keepalive = !u->headers_in.connection_close; 2370 u->keepalive = !u->headers_in.connection_close;
2348 u->length = 0; 2371 u->length = 0;
2372
2373 if (buf->pos != buf->last) {
2374 ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
2375 "upstream sent data after final chunk");
2376 u->keepalive = 0;
2377 }
2349 2378
2350 break; 2379 break;
2351 } 2380 }
2352 2381
2353 if (rc == NGX_AGAIN) { 2382 if (rc == NGX_AGAIN) {