diff src/http/modules/proxy/ngx_http_proxy_handler.c @ 34:aab2ea7c0458 NGINX_0_1_17

nginx 0.1.17 *) Change: the ngx_http_rewrite_module was rewritten from the scratch. Now it is possible to redirect, to return the error codes, to check the variables and referrers. The directives can be used inside locations. The redirect directive was canceled. *) Feature: the ngx_http_geo_module. *) Feature: the proxy_set_x_var and fastcgi_set_var directives. *) Bugfix: the location configuration with "=" modifier may be used in another location. *) Bugfix: the correct content type was set only for requests that use small caps letters in extension. *) Bugfix: if the proxy_pass or fastcgi_pass directives were set in the location, and access was denied, and the error was redirected to a static page, then the segmentation fault occurred. *) Bugfix: if in a proxied "Location" header was a relative URL, then a host name and a slash were added to them; bug appeared in 0.1.14. *) Bugfix: the system error message was not logged on Linux.
author Igor Sysoev <http://sysoev.ru>
date Thu, 03 Feb 2005 00:00:00 +0300
parents da8c190bdaba
children a39d1b793287
line wrap: on
line diff
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -36,6 +36,8 @@ static char *ngx_http_proxy_set_pass(ngx
 static char *ngx_http_proxy_parse_upstream(ngx_str_t *url,
                                            ngx_http_proxy_upstream_conf_t *u);
 
+static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
+                                      void *conf);
 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data);
 
 static ngx_conf_post_t  ngx_http_proxy_lowat_post =
@@ -119,6 +121,13 @@ static ngx_command_t  ngx_http_proxy_com
       offsetof(ngx_http_proxy_loc_conf_t, set_x_real_ip),
       NULL },
 
+    { ngx_string("proxy_set_x_var"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+      ngx_http_proxy_set_x_var,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      0,
+      NULL },
+
     { ngx_string("proxy_add_x_forwarded_for"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
       ngx_conf_set_flag_slot,
@@ -1063,9 +1072,9 @@ static void *ngx_http_proxy_create_loc_c
 {
     ngx_http_proxy_loc_conf_t  *conf;
 
-    ngx_test_null(conf,
-                  ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)),
-                  NGX_CONF_ERROR);
+    if (!(conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_proxy_loc_conf_t)))) {
+        return NGX_CONF_ERROR;
+    }
 
     /*
      * set by ngx_pcalloc():
@@ -1078,6 +1087,7 @@ static void *ngx_http_proxy_create_loc_c
      *    conf->peers = NULL;
      *    conf->cache_path = NULL;
      *    conf->temp_path = NULL;
+     *    conf->x_vars;
      *    conf->busy_lock = NULL;
      */
 
@@ -1305,6 +1315,8 @@ static char *ngx_http_proxy_set_pass(ngx
         return NGX_CONF_ERROR;
     }
 
+    lcf->upstream->url = *url;
+
     if (ngx_strncasecmp(url->data + 7, "unix:", 5) == 0) {
 
 #if (NGX_HAVE_UNIX_DOMAIN)
@@ -1367,6 +1379,47 @@ static char *ngx_http_proxy_set_pass(ngx
 }
 
 
+static char *ngx_http_proxy_set_x_var(ngx_conf_t *cf, ngx_command_t *cmd,
+                                      void *conf)
+{
+    ngx_http_proxy_loc_conf_t *lcf = conf;
+
+    ngx_uint_t                  i, *index;
+    ngx_str_t                  *value;
+    ngx_http_variable_t        *var;
+    ngx_http_core_main_conf_t  *cmcf;
+
+    if (lcf->x_vars.elts == NULL) {
+        if (ngx_array_init(&lcf->x_vars, cf->pool, 4,
+                           sizeof(ngx_http_variable_t *)) == NGX_ERROR)
+        {
+            return NGX_CONF_ERROR;
+        }
+    }
+
+    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
+
+    value = cf->args->elts;
+
+    var = cmcf->variables.elts;
+    for (i = 0; i < cmcf->variables.nelts; i++) {
+        if (ngx_strcasecmp(var[i].name.data, value[1].data) == 0) {
+
+            if (!(index = ngx_array_push(&lcf->x_vars))) {
+                return NGX_CONF_ERROR;
+            }
+
+            *index = var[i].index;
+            return NGX_CONF_OK;
+        }
+    }
+
+    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
+                       "unknown variable name \"%V\"", &value[1]);
+    return NGX_CONF_ERROR;
+}
+
+
 static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data)
 {
 #if (NGX_FREEBSD)