comparison src/http/modules/ngx_http_rewrite_module.c @ 546:e19e5f542878 NGINX_0_8_25

nginx 0.8.25 *) Change: now no message is written in an error log if a variable is not found by $r->variable() method. *) Feature: the ngx_http_degradation_module. *) Feature: regular expression named captures. *) Feature: now URI part is not required a "proxy_pass" directive if variables are used. *) Feature: now the "msie_padding" directive works for Chrome too. *) Bugfix: a segmentation fault occurred in a worker process on low memory condition; the bug had appeared in 0.8.18. *) Bugfix: nginx sent gzipped responses to clients those do not support gzip, if "gzip_static on" and "gzip_vary off"; the bug had appeared in 0.8.16.
author Igor Sysoev <http://sysoev.ru>
date Mon, 16 Nov 2009 00:00:00 +0300
parents f7ec98e3caeb
children ff463db0be31
comparison
equal deleted inserted replaced
545:91e4b06e1a01 546:e19e5f542878
292 static char * 292 static char *
293 ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 293 ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
294 { 294 {
295 ngx_http_rewrite_loc_conf_t *lcf = conf; 295 ngx_http_rewrite_loc_conf_t *lcf = conf;
296 296
297 ngx_str_t *value, err; 297 ngx_str_t *value;
298 ngx_int_t n;
299 ngx_uint_t last; 298 ngx_uint_t last;
299 ngx_regex_compile_t rc;
300 ngx_http_script_code_pt *code; 300 ngx_http_script_code_pt *code;
301 ngx_http_script_compile_t sc; 301 ngx_http_script_compile_t sc;
302 ngx_http_script_regex_code_t *regex; 302 ngx_http_script_regex_code_t *regex;
303 ngx_http_script_regex_end_code_t *regex_end; 303 ngx_http_script_regex_end_code_t *regex_end;
304 u_char errstr[NGX_MAX_CONF_ERRSTR]; 304 u_char errstr[NGX_MAX_CONF_ERRSTR];
311 311
312 ngx_memzero(regex, sizeof(ngx_http_script_regex_code_t)); 312 ngx_memzero(regex, sizeof(ngx_http_script_regex_code_t));
313 313
314 value = cf->args->elts; 314 value = cf->args->elts;
315 315
316 err.len = NGX_MAX_CONF_ERRSTR; 316 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
317 err.data = errstr; 317
318 rc.pattern = value[1];
319 rc.err.len = NGX_MAX_CONF_ERRSTR;
320 rc.err.data = errstr;
318 321
319 /* TODO: NGX_REGEX_CASELESS */ 322 /* TODO: NGX_REGEX_CASELESS */
320 323
321 regex->regex = ngx_regex_compile(&value[1], 0, cf->pool, &err); 324 regex->regex = ngx_http_regex_compile(cf, &rc);
322
323 if (regex->regex == NULL) { 325 if (regex->regex == NULL) {
324 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
325 return NGX_CONF_ERROR; 326 return NGX_CONF_ERROR;
326 } 327 }
327 328
328 regex->code = ngx_http_script_regex_start_code; 329 regex->code = ngx_http_script_regex_start_code;
329 regex->uri = 1; 330 regex->uri = 1;
392 return NGX_CONF_ERROR; 393 return NGX_CONF_ERROR;
393 } 394 }
394 395
395 regex = sc.main; 396 regex = sc.main;
396 397
397 regex->ncaptures = sc.ncaptures;
398 regex->size = sc.size; 398 regex->size = sc.size;
399 regex->args = sc.args; 399 regex->args = sc.args;
400 400
401 if (sc.variables == 0 && !sc.dup_capture) { 401 if (sc.variables == 0 && !sc.dup_capture) {
402 regex->lengths = NULL; 402 regex->lengths = NULL;
403 }
404
405 n = ngx_regex_capture_count(regex->regex);
406
407 if (n < 0) {
408 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
409 ngx_regex_capture_count_n " failed for "
410 "pattern \"%V\"", &value[1]);
411 return NGX_CONF_ERROR;
412 }
413
414 if (regex->ncaptures > (ngx_uint_t) n) {
415 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
416 "pattern \"%V\" has less captures "
417 "than referrenced in substitution \"%V\"",
418 &value[1], &value[2]);
419 return NGX_CONF_ERROR;
420 }
421
422 if (regex->ncaptures < (ngx_uint_t) n) {
423 regex->ncaptures = (ngx_uint_t) n;
424 }
425
426 if (regex->ncaptures) {
427 regex->ncaptures = (regex->ncaptures + 1) * 3;
428 } 403 }
429 404
430 regex_end = ngx_http_script_add_code(lcf->codes, 405 regex_end = ngx_http_script_add_code(lcf->codes,
431 sizeof(ngx_http_script_regex_end_code_t), 406 sizeof(ngx_http_script_regex_end_code_t),
432 &regex); 407 &regex);
622 static char * 597 static char *
623 ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf) 598 ngx_http_rewrite_if_condition(ngx_conf_t *cf, ngx_http_rewrite_loc_conf_t *lcf)
624 { 599 {
625 u_char *p; 600 u_char *p;
626 size_t len; 601 size_t len;
627 ngx_str_t *value, err; 602 ngx_str_t *value;
628 ngx_uint_t cur, last, n; 603 ngx_uint_t cur, last;
604 ngx_regex_compile_t rc;
629 ngx_http_script_code_pt *code; 605 ngx_http_script_code_pt *code;
630 ngx_http_script_file_code_t *fop; 606 ngx_http_script_file_code_t *fop;
631 ngx_http_script_regex_code_t *regex; 607 ngx_http_script_regex_code_t *regex;
632 u_char errstr[NGX_MAX_CONF_ERRSTR]; 608 u_char errstr[NGX_MAX_CONF_ERRSTR];
633 609
731 return NGX_CONF_ERROR; 707 return NGX_CONF_ERROR;
732 } 708 }
733 709
734 ngx_memzero(regex, sizeof(ngx_http_script_regex_code_t)); 710 ngx_memzero(regex, sizeof(ngx_http_script_regex_code_t));
735 711
736 err.len = NGX_MAX_CONF_ERRSTR; 712 ngx_memzero(&rc, sizeof(ngx_regex_compile_t));
737 err.data = errstr; 713
738 714 rc.pattern = value[last];
739 regex->regex = ngx_regex_compile(&value[last], 715 rc.options = (p[len - 1] == '*') ? NGX_REGEX_CASELESS : 0;
740 (p[len - 1] == '*') ? NGX_REGEX_CASELESS : 0, 716 rc.err.len = NGX_MAX_CONF_ERRSTR;
741 cf->pool, &err); 717 rc.err.data = errstr;
742 718
719 regex->regex = ngx_http_regex_compile(cf, &rc);
743 if (regex->regex == NULL) { 720 if (regex->regex == NULL) {
744 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%s", err.data);
745 return NGX_CONF_ERROR; 721 return NGX_CONF_ERROR;
746 } 722 }
747 723
748 regex->code = ngx_http_script_regex_start_code; 724 regex->code = ngx_http_script_regex_start_code;
749 regex->next = sizeof(ngx_http_script_regex_code_t); 725 regex->next = sizeof(ngx_http_script_regex_code_t);
750 regex->test = 1; 726 regex->test = 1;
751 if (p[0] == '!') { 727 if (p[0] == '!') {
752 regex->negative_test = 1; 728 regex->negative_test = 1;
753 } 729 }
754 regex->name = value[last]; 730 regex->name = value[last];
755
756 n = ngx_regex_capture_count(regex->regex);
757
758 if (n) {
759 regex->ncaptures = (n + 1) * 3;
760 }
761 731
762 return NGX_CONF_OK; 732 return NGX_CONF_OK;
763 } 733 }
764 734
765 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 735 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,