diff src/http/modules/ngx_http_proxy_module.c @ 614:bb20316269e4 NGINX_0_9_5

nginx 0.9.5 *) Change: now nginx uses a default listen backlog value -1 on Linux. Thanks to Andrei Nigmatulin. *) Feature: the "utf8" parameter of "geoip_country" and "geoip_city" directives. Thanks to Denis F. Latypoff. *) Bugfix: in a default "proxy_redirect" directive if "proxy_pass" directive has no URI part. Thanks to Maxim Dounin. *) Bugfix: an "error_page" directive did not work with nonstandard error codes; the bug had appeared in 0.8.53. Thanks to Maxim Dounin.
author Igor Sysoev <http://sysoev.ru>
date Mon, 21 Feb 2011 00:00:00 +0300
parents 09d5f308901f
children 5b73504dd4ba
line wrap: on
line diff
--- a/src/http/modules/ngx_http_proxy_module.c
+++ b/src/http/modules/ngx_http_proxy_module.c
@@ -1717,6 +1717,7 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t
     ngx_http_proxy_loc_conf_t *prev = parent;
     ngx_http_proxy_loc_conf_t *conf = child;
 
+    u_char                     *p;
     size_t                      size;
     ngx_keyval_t               *s;
     ngx_hash_init_t             hash;
@@ -1975,13 +1976,25 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t
             }
 
             pr->handler = ngx_http_proxy_rewrite_redirect_text;
-            pr->redirect = conf->url;
 
             if (conf->vars.uri.len) {
+                pr->redirect = conf->url;
                 pr->replacement.text = conf->location;
 
             } else {
-                ngx_str_null(&pr->replacement.text);
+                pr->redirect.len = conf->url.len + sizeof("/") - 1;
+
+                p = ngx_pnalloc(cf->pool, pr->redirect.len);
+                if (p == NULL) {
+                    return NGX_CONF_ERROR;
+                }
+
+                pr->redirect.data = p;
+
+                p = ngx_cpymem(p, conf->url.data, conf->url.len);
+                *p = '/';
+
+                ngx_str_set(&pr->replacement.text, "/");
             }
         }
     }
@@ -2456,6 +2469,7 @@ ngx_http_proxy_redirect(ngx_conf_t *cf, 
 {
     ngx_http_proxy_loc_conf_t *plcf = conf;
 
+    u_char                     *p;
     ngx_str_t                  *value;
     ngx_array_t                *vars_lengths, *vars_values;
     ngx_http_script_compile_t   sc;
@@ -2518,13 +2532,25 @@ ngx_http_proxy_redirect(ngx_conf_t *cf, 
         }
 
         pr->handler = ngx_http_proxy_rewrite_redirect_text;
-        pr->redirect = plcf->url;
 
         if (plcf->vars.uri.len) {
+            pr->redirect = plcf->url;
             pr->replacement.text = plcf->location;
 
         } else {
-            ngx_str_null(&pr->replacement.text);
+            pr->redirect.len = plcf->url.len + sizeof("/") - 1;
+
+            p = ngx_pnalloc(cf->pool, pr->redirect.len);
+            if (p == NULL) {
+                return NGX_CONF_ERROR;
+            }
+
+            pr->redirect.data = p;
+
+            p = ngx_cpymem(p, plcf->url.data, plcf->url.len);
+            *p = '/';
+
+            ngx_str_set(&pr->replacement.text, "/");
         }
 
         return NGX_CONF_OK;