[nginx] svn commit: r4399 - trunk/src/http/modules

vbart at nginx.com vbart at nginx.com
Tue Jan 10 15:09:45 UTC 2012


Author: vbart
Date: 2012-01-10 15:09:45 +0000 (Tue, 10 Jan 2012)
New Revision: 4399

Modified:
   trunk/src/http/modules/ngx_http_proxy_module.c
Log:
Fixed: proxy_redirect with regex might broke Refresh header.

The problem was localized in ngx_http_proxy_rewrite_redirect_regex() handler
function which did not take into account prefix when overwriting header value.


Modified: trunk/src/http/modules/ngx_http_proxy_module.c
===================================================================
--- trunk/src/http/modules/ngx_http_proxy_module.c	2012-01-10 07:28:32 UTC (rev 4398)
+++ trunk/src/http/modules/ngx_http_proxy_module.c	2012-01-10 15:09:45 UTC (rev 4399)
@@ -2348,6 +2348,8 @@
 ngx_http_proxy_rewrite_redirect_regex(ngx_http_request_t *r, ngx_table_elt_t *h,
     size_t prefix, ngx_http_proxy_redirect_t *pr)
 {
+    size_t      len;
+    u_char     *data;
     ngx_str_t   redirect, replacement;
 
     redirect.len = h->value.len - prefix;
@@ -2361,8 +2363,24 @@
         return NGX_ERROR;
     }
 
-    h->value = replacement;
+    if (!prefix) {
+        h->value = replacement;
+        return NGX_OK;
+    }
 
+    len = prefix + replacement.len;
+
+    data = ngx_pnalloc(r->pool, len);
+    if (data == NULL) {
+        return NGX_ERROR;
+    }
+
+    ngx_memcpy(data, h->value.data, prefix);
+    ngx_memcpy(data + prefix, replacement.data, replacement.len);
+
+    h->value.len = len;
+    h->value.data = data;
+
     return NGX_OK;
 }
 



More information about the nginx-devel mailing list