Mercurial > hg > nginx
comparison src/http/ngx_http_variables.c @ 9262:106b3832e7ef
Modified $content_length to match available request body length.
As long as the request body was discarded or there was an error during
reading, it now follows r->headers_in.content_length_n and reflects the
fact that no request body is available, similarly to how Content-Length
as used by the proxy module does.
This makes complex processing of various error pages safer, notably when
using fastcgi_pass, uwsgi_pass, or grpc_pass, where the $content_length
variable is used to set length.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 27 Apr 2024 18:23:22 +0300 |
parents | b71e69247483 |
children | 388a801e9bb9 |
comparison
equal
deleted
inserted
replaced
9261:f798ecafec05 | 9262:106b3832e7ef |
---|---|
1182 ngx_http_variable_content_length(ngx_http_request_t *r, | 1182 ngx_http_variable_content_length(ngx_http_request_t *r, |
1183 ngx_http_variable_value_t *v, uintptr_t data) | 1183 ngx_http_variable_value_t *v, uintptr_t data) |
1184 { | 1184 { |
1185 u_char *p; | 1185 u_char *p; |
1186 | 1186 |
1187 if (r->headers_in.content_length) { | 1187 if (r->reading_body && r->headers_in.content_length) { |
1188 v->len = r->headers_in.content_length->value.len; | 1188 v->len = r->headers_in.content_length->value.len; |
1189 v->data = r->headers_in.content_length->value.data; | 1189 v->data = r->headers_in.content_length->value.data; |
1190 v->valid = 1; | 1190 v->valid = 1; |
1191 v->no_cacheable = 0; | 1191 v->no_cacheable = 1; |
1192 v->not_found = 0; | 1192 v->not_found = 0; |
1193 | 1193 |
1194 } else if (r->reading_body) { | 1194 } else if (r->reading_body) { |
1195 v->not_found = 1; | 1195 v->not_found = 1; |
1196 v->no_cacheable = 1; | 1196 v->no_cacheable = 1; |
1197 | |
1198 } else if (r->discard_body) { | |
1199 v->len = 1; | |
1200 v->data = (u_char *) "0"; | |
1201 v->valid = 1; | |
1202 v->no_cacheable = 0; | |
1203 v->not_found = 0; | |
1197 | 1204 |
1198 } else if (r->headers_in.content_length_n >= 0) { | 1205 } else if (r->headers_in.content_length_n >= 0) { |
1199 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); | 1206 p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN); |
1200 if (p == NULL) { | 1207 if (p == NULL) { |
1201 return NGX_ERROR; | 1208 return NGX_ERROR; |
1202 } | 1209 } |
1203 | 1210 |
1204 v->len = ngx_sprintf(p, "%O", r->headers_in.content_length_n) - p; | 1211 v->len = ngx_sprintf(p, "%O", r->headers_in.content_length_n) - p; |
1205 v->data = p; | 1212 v->data = p; |
1206 v->valid = 1; | 1213 v->valid = 1; |
1207 v->no_cacheable = 0; | 1214 v->no_cacheable = 1; |
1208 v->not_found = 0; | 1215 v->not_found = 0; |
1209 | 1216 |
1210 } else if (r->headers_in.chunked) { | 1217 } else if (r->headers_in.chunked) { |
1211 v->not_found = 1; | 1218 v->not_found = 1; |
1212 v->no_cacheable = 1; | 1219 v->no_cacheable = 1; |