comparison src/http/modules/ngx_http_scgi_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 8b68d50090e4
children b87b7092cedb
comparison
equal deleted inserted replaced
7677:a786e491d08d 7678:bffcc5af1d72
47 ngx_http_scgi_loc_conf_t *scf); 47 ngx_http_scgi_loc_conf_t *scf);
48 static ngx_int_t ngx_http_scgi_create_request(ngx_http_request_t *r); 48 static ngx_int_t ngx_http_scgi_create_request(ngx_http_request_t *r);
49 static ngx_int_t ngx_http_scgi_reinit_request(ngx_http_request_t *r); 49 static ngx_int_t ngx_http_scgi_reinit_request(ngx_http_request_t *r);
50 static ngx_int_t ngx_http_scgi_process_status_line(ngx_http_request_t *r); 50 static ngx_int_t ngx_http_scgi_process_status_line(ngx_http_request_t *r);
51 static ngx_int_t ngx_http_scgi_process_header(ngx_http_request_t *r); 51 static ngx_int_t ngx_http_scgi_process_header(ngx_http_request_t *r);
52 static ngx_int_t ngx_http_scgi_input_filter_init(void *data);
52 static void ngx_http_scgi_abort_request(ngx_http_request_t *r); 53 static void ngx_http_scgi_abort_request(ngx_http_request_t *r);
53 static void ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc); 54 static void ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc);
54 55
55 static void *ngx_http_scgi_create_main_conf(ngx_conf_t *cf); 56 static void *ngx_http_scgi_create_main_conf(ngx_conf_t *cf);
56 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf); 57 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf);
531 return NGX_HTTP_INTERNAL_SERVER_ERROR; 532 return NGX_HTTP_INTERNAL_SERVER_ERROR;
532 } 533 }
533 534
534 u->pipe->input_filter = ngx_event_pipe_copy_input_filter; 535 u->pipe->input_filter = ngx_event_pipe_copy_input_filter;
535 u->pipe->input_ctx = r; 536 u->pipe->input_ctx = r;
537
538 u->input_filter_init = ngx_http_scgi_input_filter_init;
539 u->input_filter = ngx_http_upstream_non_buffered_filter;
540 u->input_filter_ctx = r;
536 541
537 if (!scf->upstream.request_buffering 542 if (!scf->upstream.request_buffering
538 && scf->upstream.pass_request_body 543 && scf->upstream.pass_request_body
539 && !r->headers_in.chunked) 544 && !r->headers_in.chunked)
540 { 545 {
1143 return NGX_HTTP_UPSTREAM_INVALID_HEADER; 1148 return NGX_HTTP_UPSTREAM_INVALID_HEADER;
1144 } 1149 }
1145 } 1150 }
1146 1151
1147 1152
1153 static ngx_int_t
1154 ngx_http_scgi_input_filter_init(void *data)
1155 {
1156 ngx_http_request_t *r = data;
1157 ngx_http_upstream_t *u;
1158
1159 u = r->upstream;
1160
1161 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1162 "http scgi filter init s:%ui l:%O",
1163 u->headers_in.status_n, u->headers_in.content_length_n);
1164
1165 if (u->headers_in.status_n == NGX_HTTP_NO_CONTENT
1166 || u->headers_in.status_n == NGX_HTTP_NOT_MODIFIED)
1167 {
1168 u->pipe->length = 0;
1169 u->length = 0;
1170
1171 } else if (r->method == NGX_HTTP_HEAD) {
1172 u->pipe->length = -1;
1173 u->length = -1;
1174
1175 } else {
1176 u->pipe->length = u->headers_in.content_length_n;
1177 u->length = u->headers_in.content_length_n;
1178 }
1179
1180 return NGX_OK;
1181 }
1182
1183
1148 static void 1184 static void
1149 ngx_http_scgi_abort_request(ngx_http_request_t *r) 1185 ngx_http_scgi_abort_request(ngx_http_request_t *r)
1150 { 1186 {
1151 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 1187 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1152 "abort http scgi request"); 1188 "abort http scgi request");