changeset 2589:859f6675a553

use complex value in error_page
author Igor Sysoev <igor@sysoev.ru>
date Sun, 22 Mar 2009 09:40:04 +0000
parents a6954ce88b80
children c65755e03084
files src/http/ngx_http.h src/http/ngx_http_core_module.c src/http/ngx_http_core_module.h src/http/ngx_http_special_response.c
diffstat 4 files changed, 46 insertions(+), 97 deletions(-) [+]
line wrap: on
line diff
--- a/src/http/ngx_http.h
+++ b/src/http/ngx_http.h
@@ -35,8 +35,8 @@ typedef u_char *(*ngx_http_log_handler_p
 #include <ngx_http_upstream_round_robin.h>
 #include <ngx_http_config.h>
 #include <ngx_http_busy_lock.h>
+#include <ngx_http_script.h>
 #include <ngx_http_core_module.h>
-#include <ngx_http_script.h>
 
 #if (NGX_HTTP_SSI)
 #include <ngx_http_ssi_filter_module.h>
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -3791,13 +3791,13 @@ ngx_http_core_error_page(ngx_conf_t *cf,
 {
     ngx_http_core_loc_conf_t *lcf = conf;
 
-    u_char                     *args;
-    ngx_int_t                   overwrite;
-    ngx_str_t                  *value, uri;
-    ngx_uint_t                  i, n, nvar;
-    ngx_array_t                *uri_lengths, *uri_values;
-    ngx_http_err_page_t        *err;
-    ngx_http_script_compile_t   sc;
+    u_char                            *p;
+    ngx_int_t                          overwrite;
+    ngx_str_t                         *value, uri, args;
+    ngx_uint_t                         i, n;
+    ngx_http_err_page_t               *err;
+    ngx_http_complex_value_t           cv;
+    ngx_http_compile_complex_value_t   ccv;
 
     if (lcf->error_pages == NULL) {
         lcf->error_pages = ngx_array_create(cf->pool, 4,
@@ -3839,29 +3839,32 @@ ngx_http_core_error_page(ngx_conf_t *cf,
     }
 
     uri = value[cf->args->nelts - 1];
-    uri_lengths = NULL;
-    uri_values = NULL;
-
-    nvar = ngx_http_script_variables_count(&uri);
-
-    if (nvar) {
-        ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
-
-        sc.cf = cf;
-        sc.source = &uri;
-        sc.lengths = &uri_lengths;
-        sc.values = &uri_values;
-        sc.variables = nvar;
-        sc.complete_lengths = 1;
-        sc.complete_values = 1;
-
-        if (ngx_http_script_compile(&sc) != NGX_OK) {
-            return NGX_CONF_ERROR;
+
+    ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
+
+    ccv.cf = cf;
+    ccv.value = &uri;
+    ccv.complex_value = &cv;
+
+    if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
+        return NGX_CONF_ERROR;
+    }
+
+    args.len = 0;
+    args.data = NULL;
+
+    if (cv.lengths == NULL) {
+        p = (u_char *) ngx_strchr(uri.data, '?');
+
+        if (p) {
+            cv.value.len = p - uri.data;
+            cv.value.data = uri.data;
+            p++;
+            args.len = (uri.data + uri.len) - p;
+            args.data = p;
         }
     }
 
-    args = (u_char *) ngx_strchr(uri.data, '?');
-
     for (i = 1; i < cf->args->nelts - n; i++) {
         err = ngx_array_push(lcf->error_pages);
         if (err == NULL) {
@@ -3900,21 +3903,8 @@ ngx_http_core_error_page(ngx_conf_t *cf,
             }
         }
 
-        if (args) {
-            err->uri.len = args - uri.data;
-            err->uri.data = uri.data;
-            args++;
-            err->args.len = (uri.data + uri.len) - args;
-            err->args.data = args;
-
-        } else {
-            err->uri = uri;
-            err->args.len = 0;
-            err->args.data = NULL;
-        }
-
-        err->uri_lengths = uri_lengths;
-        err->uri_values = uri_values;
+        err->value = cv;
+	err->args = args;
     }
 
     return NGX_CONF_OK;
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -258,10 +258,8 @@ struct ngx_http_server_name_s {
 typedef struct {
     ngx_int_t                  status;
     ngx_int_t                  overwrite;
-    ngx_str_t                  uri;
+    ngx_http_complex_value_t   value;
     ngx_str_t                  args;
-    ngx_array_t               *uri_lengths;
-    ngx_array_t               *uri_values;
 } ngx_http_err_page_t;
 
 
--- a/src/http/ngx_http_special_response.c
+++ b/src/http/ngx_http_special_response.c
@@ -432,9 +432,8 @@ ngx_http_special_response_handler(ngx_ht
 static ngx_int_t
 ngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)
 {
-    u_char                     ch, *p, *last;
     ngx_int_t                  overwrite;
-    ngx_str_t                 *uri, *args, u, a;
+    ngx_str_t                  uri, args;
     ngx_table_elt_t           *location;
     ngx_http_core_loc_conf_t  *clcf;
 
@@ -448,67 +447,29 @@ ngx_http_send_error_page(ngx_http_reques
 
     r->zero_in_uri = 0;
 
-    if (err_page->uri_lengths) {
-        if (ngx_http_script_run(r, &u, err_page->uri_lengths->elts, 0,
-                                err_page->uri_values->elts)
-            == NULL)
-        {
-            return NGX_ERROR;
-        }
-
-        p = u.data;
-        uri = &u;
-        args = NULL;
-
-        if (*p == '/') {
-
-            last = p + uri->len;
-
-            while (p < last) {
-
-                ch = *p++;
+    if (ngx_http_complex_value(r, &err_page->value, &uri) != NGX_OK) {
+        return NGX_ERROR;
+    }
 
-                if (ch == '?') {
-                    a.len = last - p;
-                    a.data = p;
-                    args = &a;
-
-                    u.len = p - 1 - u.data;
-
-                    while (p < last) {
-                        if (*p++ == '\0') {
-                            r->zero_in_uri = 1;
-                            break;
-                        }
-                    }
-
-                    break;
-                }
-
-                if (ch == '\0') {
-                    r->zero_in_uri = 1;
-                    continue;
-                }
-            }
-        }
+    if (err_page->value.lengths) {
+        ngx_http_split_args(r, &uri, &args);
 
     } else {
-        uri = &err_page->uri;
-        args = &err_page->args;
+        args = err_page->args;
     }
 
-    if (uri->data[0] == '/') {
+    if (uri.data[0] == '/') {
 
         if (r->method != NGX_HTTP_HEAD) {
             r->method = NGX_HTTP_GET;
             r->method_name = ngx_http_get_name;
         }
 
-        return ngx_http_internal_redirect(r, uri, args);
+        return ngx_http_internal_redirect(r, &uri, &args);
     }
 
-    if (uri->data[0] == '@') {
-        return ngx_http_named_location(r, uri);
+    if (uri.data[0] == '@') {
+        return ngx_http_named_location(r, &uri);
     }
 
     location = ngx_list_push(&r->headers_out.headers);
@@ -522,7 +483,7 @@ ngx_http_send_error_page(ngx_http_reques
     location->hash = 1;
     location->key.len = sizeof("Location") - 1;
     location->key.data = (u_char *) "Location";
-    location->value = *uri;
+    location->value = uri;
 
     r->headers_out.location = location;