comparison src/http/modules/ngx_http_rewrite_module.c @ 580:4d3e880ce86c NGINX_0_8_42

nginx 0.8.42 *) Change: now nginx tests locations given by regular expressions, if request was matched exactly by a location given by a prefix string. The previous behavior has been introduced in 0.7.1. *) Feature: the ngx_http_scgi_module. Thanks to Manlio Perillo. *) Feature: a text answer may be added to a "return" directive.
author Igor Sysoev <http://sysoev.ru>
date Mon, 21 Jun 2010 00:00:00 +0400
parents ff463db0be31
children d3cf6c6b0043
comparison
equal deleted inserted replaced
579:c570633043e7 580:4d3e880ce86c
50 0, 50 0,
51 NULL }, 51 NULL },
52 52
53 { ngx_string("return"), 53 { ngx_string("return"),
54 NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF 54 NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
55 |NGX_CONF_TAKE1, 55 |NGX_CONF_TAKE12,
56 ngx_http_rewrite_return, 56 ngx_http_rewrite_return,
57 NGX_HTTP_LOC_CONF_OFFSET, 57 NGX_HTTP_LOC_CONF_OFFSET,
58 0, 58 0,
59 NULL }, 59 NULL },
60 60
431 static char * 431 static char *
432 ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 432 ngx_http_rewrite_return(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
433 { 433 {
434 ngx_http_rewrite_loc_conf_t *lcf = conf; 434 ngx_http_rewrite_loc_conf_t *lcf = conf;
435 435
436 ngx_str_t *value; 436 u_char *p;
437 ngx_http_script_return_code_t *ret; 437 ngx_str_t *value, *v;
438 ngx_http_script_return_code_t *ret;
439 ngx_http_compile_complex_value_t ccv;
438 440
439 ret = ngx_http_script_start_code(cf->pool, &lcf->codes, 441 ret = ngx_http_script_start_code(cf->pool, &lcf->codes,
440 sizeof(ngx_http_script_return_code_t)); 442 sizeof(ngx_http_script_return_code_t));
441 if (ret == NULL) { 443 if (ret == NULL) {
442 return NGX_CONF_ERROR; 444 return NGX_CONF_ERROR;
443 } 445 }
444 446
445 value = cf->args->elts; 447 value = cf->args->elts;
446 448
449 ngx_memzero(ret, sizeof(ngx_http_script_return_code_t));
450
447 ret->code = ngx_http_script_return_code; 451 ret->code = ngx_http_script_return_code;
448 ret->null = (uintptr_t) NULL; 452
449 453 p = value[1].data;
450 ret->status = ngx_atoi(value[1].data, value[1].len); 454
455 ret->status = ngx_atoi(p, value[1].len);
451 456
452 if (ret->status == (uintptr_t) NGX_ERROR) { 457 if (ret->status == (uintptr_t) NGX_ERROR) {
458
459 if (cf->args->nelts == 2
460 && (ngx_strncmp(p, "http://", sizeof("http://") - 1) == 0
461 || ngx_strncmp(p, "https://", sizeof("https://") - 1) == 0
462 || ngx_strncmp(p, "$scheme", sizeof("$scheme") - 1) == 0))
463 {
464 ret->status = NGX_HTTP_MOVED_TEMPORARILY;
465 v = &value[1];
466
467 } else {
468 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
469 "invalid return code \"%V\"", &value[1]);
470 return NGX_CONF_ERROR;
471 }
472
473 } else {
474
475 if (cf->args->nelts == 2) {
476 return NGX_CONF_OK;
477 }
478
479 v = &value[2];
480 }
481
482 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
483
484 ccv.cf = cf;
485 ccv.value = v;
486 ccv.complex_value = &ret->text;
487
488 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
453 return NGX_CONF_ERROR; 489 return NGX_CONF_ERROR;
454 } 490 }
455 491
456 return NGX_CONF_OK; 492 return NGX_CONF_OK;
457 } 493 }