Mercurial > hg > nginx
comparison src/http/modules/ngx_http_uwsgi_module.c @ 7678:bffcc5af1d72
Upstream: 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.
This change covers generic buffered and unbuffered filters as used
in the scgi and uwsgi modules. Appropriate input filter init
handlers are provided by the scgi and uwsgi modules to set corresponding
lengths.
Note that for responses to HEAD requests there is an exception:
we do allow any response length. This is because responses to HEAD
requests might be actual full responses, and it is up to nginx
to remove the response body. If caching is enabled, only full
responses matching the Content-Length header will be cached
(see b779728b180c).
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 06 Jul 2020 18:36:22 +0300 |
parents | 8cf31489b479 |
children | 1a719ee45526 |
comparison
equal
deleted
inserted
replaced
7677:a786e491d08d | 7678:bffcc5af1d72 |
---|---|
65 ngx_http_uwsgi_loc_conf_t *uwcf); | 65 ngx_http_uwsgi_loc_conf_t *uwcf); |
66 static ngx_int_t ngx_http_uwsgi_create_request(ngx_http_request_t *r); | 66 static ngx_int_t ngx_http_uwsgi_create_request(ngx_http_request_t *r); |
67 static ngx_int_t ngx_http_uwsgi_reinit_request(ngx_http_request_t *r); | 67 static ngx_int_t ngx_http_uwsgi_reinit_request(ngx_http_request_t *r); |
68 static ngx_int_t ngx_http_uwsgi_process_status_line(ngx_http_request_t *r); | 68 static ngx_int_t ngx_http_uwsgi_process_status_line(ngx_http_request_t *r); |
69 static ngx_int_t ngx_http_uwsgi_process_header(ngx_http_request_t *r); | 69 static ngx_int_t ngx_http_uwsgi_process_header(ngx_http_request_t *r); |
70 static ngx_int_t ngx_http_uwsgi_input_filter_init(void *data); | |
70 static void ngx_http_uwsgi_abort_request(ngx_http_request_t *r); | 71 static void ngx_http_uwsgi_abort_request(ngx_http_request_t *r); |
71 static void ngx_http_uwsgi_finalize_request(ngx_http_request_t *r, | 72 static void ngx_http_uwsgi_finalize_request(ngx_http_request_t *r, |
72 ngx_int_t rc); | 73 ngx_int_t rc); |
73 | 74 |
74 static void *ngx_http_uwsgi_create_main_conf(ngx_conf_t *cf); | 75 static void *ngx_http_uwsgi_create_main_conf(ngx_conf_t *cf); |
700 return NGX_HTTP_INTERNAL_SERVER_ERROR; | 701 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
701 } | 702 } |
702 | 703 |
703 u->pipe->input_filter = ngx_event_pipe_copy_input_filter; | 704 u->pipe->input_filter = ngx_event_pipe_copy_input_filter; |
704 u->pipe->input_ctx = r; | 705 u->pipe->input_ctx = r; |
706 | |
707 u->input_filter_init = ngx_http_uwsgi_input_filter_init; | |
708 u->input_filter = ngx_http_upstream_non_buffered_filter; | |
709 u->input_filter_ctx = r; | |
705 | 710 |
706 if (!uwcf->upstream.request_buffering | 711 if (!uwcf->upstream.request_buffering |
707 && uwcf->upstream.pass_request_body | 712 && uwcf->upstream.pass_request_body |
708 && !r->headers_in.chunked) | 713 && !r->headers_in.chunked) |
709 { | 714 { |
1354 return NGX_HTTP_UPSTREAM_INVALID_HEADER; | 1359 return NGX_HTTP_UPSTREAM_INVALID_HEADER; |
1355 } | 1360 } |
1356 } | 1361 } |
1357 | 1362 |
1358 | 1363 |
1364 static ngx_int_t | |
1365 ngx_http_uwsgi_input_filter_init(void *data) | |
1366 { | |
1367 ngx_http_request_t *r = data; | |
1368 ngx_http_upstream_t *u; | |
1369 | |
1370 u = r->upstream; | |
1371 | |
1372 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
1373 "http uwsgi filter init s:%ui l:%O", | |
1374 u->headers_in.status_n, u->headers_in.content_length_n); | |
1375 | |
1376 if (u->headers_in.status_n == NGX_HTTP_NO_CONTENT | |
1377 || u->headers_in.status_n == NGX_HTTP_NOT_MODIFIED) | |
1378 { | |
1379 u->pipe->length = 0; | |
1380 u->length = 0; | |
1381 | |
1382 } else if (r->method == NGX_HTTP_HEAD) { | |
1383 u->pipe->length = -1; | |
1384 u->length = -1; | |
1385 | |
1386 } else { | |
1387 u->pipe->length = u->headers_in.content_length_n; | |
1388 u->length = u->headers_in.content_length_n; | |
1389 } | |
1390 | |
1391 return NGX_OK; | |
1392 } | |
1393 | |
1394 | |
1359 static void | 1395 static void |
1360 ngx_http_uwsgi_abort_request(ngx_http_request_t *r) | 1396 ngx_http_uwsgi_abort_request(ngx_http_request_t *r) |
1361 { | 1397 { |
1362 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 1398 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
1363 "abort http uwsgi request"); | 1399 "abort http uwsgi request"); |