comparison src/http/modules/ngx_http_rewrite_module.c @ 7355:b64adc956643

Rewrite: removed r->err_status special handling (ticket #1634). Trying to look into r->err_status in the "return" directive makes it behave differently than real errors generated in other parts of the code, and is an endless source of various problems. This behaviour was introduced in 726:7b71936d5299 (0.4.4) with the comment "fix: "return" always overrode "error_page" response code". It is not clear if there were any real cases this was expected to fix, but there are several cases which are broken due to this change, some previously fixed (4147:7f64de1cc2c0). In ticket #1634, the problem is that when r->err_status is set to a non-special status code, it is not possible to return a response by simply returning r->err_status. If this is the case, the only option is to return script's e->status instead. An example configuration: location / { error_page 404 =200 /err502; return 404; } location = /err502 { return 502; } After the change, such a configuration will properly return standard 502 error, much like it happens when a 502 error is generated by proxy_pass. This also fixes the following configuration to properly close connection as clearly requested by "return 444": location / { error_page 404 /close; return 404; } location = /close { return 444; } Previously, this required "error_page 404 = /close;" to work as intended.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 21 Sep 2018 15:59:33 +0300
parents d2b2ff157da5
children db8df9cd84c8
comparison
equal deleted inserted replaced
7354:1812f1d79d84 7355:b64adc956643
178 while (*(uintptr_t *) e->ip) { 178 while (*(uintptr_t *) e->ip) {
179 code = *(ngx_http_script_code_pt *) e->ip; 179 code = *(ngx_http_script_code_pt *) e->ip;
180 code(e); 180 code(e);
181 } 181 }
182 182
183 if (e->status < NGX_HTTP_BAD_REQUEST) { 183 return e->status;
184 return e->status;
185 }
186
187 if (r->err_status == 0) {
188 return e->status;
189 }
190
191 return r->err_status;
192 } 184 }
193 185
194 186
195 static ngx_int_t 187 static ngx_int_t
196 ngx_http_rewrite_var(ngx_http_request_t *r, ngx_http_variable_value_t *v, 188 ngx_http_rewrite_var(ngx_http_request_t *r, ngx_http_variable_value_t *v,