From 56b9f427e8c187df63f65a9009b25110d06b82cc Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Tue, 10 Jan 2012 15:09:45 +0000 Subject: [PATCH] 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. --- src/http/modules/ngx_http_proxy_module.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c index b65093b72..78817cea8 100644 --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -2348,6 +2348,8 @@ static ngx_int_t 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,7 +2363,23 @@ ngx_http_proxy_rewrite_redirect_regex(ngx_http_request_t *r, ngx_table_elt_t *h, 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; }