comparison src/http/modules/ngx_http_rewrite_module.c @ 635:e67b227c8dbb default tip

Merge with current.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 25 Apr 2011 04:07:55 +0400
parents 4d3e880ce86c
children
comparison
equal deleted inserted replaced
578:f3a9e57d2e17 635:e67b227c8dbb
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
339 regex->add_args = 1; 339 regex->add_args = 1;
340 } 340 }
341 341
342 last = 0; 342 last = 0;
343 343
344 if (ngx_strncmp(value[2].data, "http://", sizeof("http://") - 1) == 0) { 344 if (ngx_strncmp(value[2].data, "http://", sizeof("http://") - 1) == 0
345 regex->status = NGX_HTTP_MOVED_TEMPORARILY; 345 || ngx_strncmp(value[2].data, "https://", sizeof("https://") - 1) == 0
346 regex->redirect = 1; 346 || ngx_strncmp(value[2].data, "$scheme", sizeof("$scheme") - 1) == 0)
347 last = 1; 347 {
348 }
349
350 if (ngx_strncmp(value[2].data, "https://", sizeof("https://") - 1) == 0) {
351 regex->status = NGX_HTTP_MOVED_TEMPORARILY; 348 regex->status = NGX_HTTP_MOVED_TEMPORARILY;
352 regex->redirect = 1; 349 regex->redirect = 1;
353 last = 1; 350 last = 1;
354 } 351 }
355 352
434 static char * 431 static char *
435 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)
436 { 433 {
437 ngx_http_rewrite_loc_conf_t *lcf = conf; 434 ngx_http_rewrite_loc_conf_t *lcf = conf;
438 435
439 ngx_str_t *value; 436 u_char *p;
440 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;
441 440
442 ret = ngx_http_script_start_code(cf->pool, &lcf->codes, 441 ret = ngx_http_script_start_code(cf->pool, &lcf->codes,
443 sizeof(ngx_http_script_return_code_t)); 442 sizeof(ngx_http_script_return_code_t));
444 if (ret == NULL) { 443 if (ret == NULL) {
445 return NGX_CONF_ERROR; 444 return NGX_CONF_ERROR;
446 } 445 }
447 446
448 value = cf->args->elts; 447 value = cf->args->elts;
449 448
449 ngx_memzero(ret, sizeof(ngx_http_script_return_code_t));
450
450 ret->code = ngx_http_script_return_code; 451 ret->code = ngx_http_script_return_code;
451 ret->null = (uintptr_t) NULL; 452
452 453 p = value[1].data;
453 ret->status = ngx_atoi(value[1].data, value[1].len); 454
455 ret->status = ngx_atoi(p, value[1].len);
454 456
455 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) {
456 return NGX_CONF_ERROR; 489 return NGX_CONF_ERROR;
457 } 490 }
458 491
459 return NGX_CONF_OK; 492 return NGX_CONF_OK;
460 } 493 }