[PATCH] Upstream: support named location for X-Accel-Redirect

Toshikuni Fukaya toshikuni-fukaya at cybozu.co.jp
Tue Nov 4 11:18:44 UTC 2014


# HG changeset patch
# User Toshikuni Fukaya <toshikuni-fukaya at cybozu.co.jp>
# Date 1415098583 -32400
# Node ID 6f4517db02a8cd4068b9378bd93fe6290f54720d
# Parent  dff86e2246a53b0f4a61935cd5c8c0a0f66d0ca2
Upstream: support named location for X-Accel-Redirect.

diff -r dff86e2246a5 -r 6f4517db02a8 src/http/ngx_http_upstream.c
--- a/src/http/ngx_http_upstream.c	Mon Aug 25 13:41:31 2014 +0400
+++ b/src/http/ngx_http_upstream.c	Tue Nov 04 19:56:23 2014 +0900
@@ -2218,19 +2218,25 @@
         }
 
         uri = u->headers_in.x_accel_redirect->value;
-        ngx_str_null(&args);
-        flags = NGX_HTTP_LOG_UNSAFE;
-
-        if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags) != NGX_OK) {
-            ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
-            return NGX_DONE;
-        }
-
-        if (r->method != NGX_HTTP_HEAD) {
-            r->method = NGX_HTTP_GET;
-        }
-
-        ngx_http_internal_redirect(r, &uri, &args);
+
+        if (uri.len > 0 && uri.data[0] == '@') {
+            ngx_http_named_location(r, &uri);
+        } else {
+            ngx_str_null(&args);
+            flags = NGX_HTTP_LOG_UNSAFE;
+
+            if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags) != NGX_OK) {
+                ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
+                return NGX_DONE;
+            }
+
+            if (r->method != NGX_HTTP_HEAD) {
+                r->method = NGX_HTTP_GET;
+            }
+
+            ngx_http_internal_redirect(r, &uri, &args);
+        }
+
         ngx_http_finalize_request(r, NGX_DONE);
         return NGX_DONE;
     }



More information about the nginx-devel mailing list