Custom headers with X-Accel-Redirect.

Eden Li eden at mojiti.com
Wed Oct 29 00:04:18 MSK 2008


The patch below seems to work in my trivial testing.  For example:

location /test {
  proxy_pass_header X-Robots-Tag;
  proxy_pass http://backend;
}

X-Robots-Tag will be passed from the backend, everything else (except
for the headers in the original email) will not.

Use at your own risk:

--- orig/nginx-0.6.32/src/http/ngx_http_upstream.c	2008-04-17
07:32:11.000000000 -0700
+++ nginx-0.6.32/src/http/ngx_http_upstream.c	2008-10-28
13:56:42.000000000 -0700
@@ -1035,8 +1035,8 @@
 {
     ssize_t                         n;
     ngx_int_t                       rc;
-    ngx_str_t                      *uri, args;
-    ngx_uint_t                      i, flags;
+    ngx_str_t                      *uri, args, *hs;
+    ngx_uint_t                      i, j, flags;
     ngx_list_part_t                *part;
     ngx_table_elt_t                *h;
     ngx_connection_t               *c;
@@ -1279,6 +1279,18 @@
                     return;
                 }
             }
+            else {
+                hs = u->conf->pass_headers->elts;
+                for (j = 0; j < u->conf->pass_headers->nelts; j++) {
+                    if (ngx_strncasecmp(hs[j].data, h[i].key.data,
hs[j].len) == 0) {
+                        if (ngx_http_upstream_copy_header_line(r,
&h[i], 0) != NGX_OK) {
+                            ngx_http_finalize_request(r,
NGX_HTTP_INTERNAL_SERVER_ERROR);
+                            return;
+                        }
+                        break;
+                    }
+                }
+            }
         }

         uri = &u->headers_in.x_accel_redirect->value;

On Tue, Oct 28, 2008 at 8:50 AM, Thomas Witt <thomas.witt at infopark.de> wrote:
> Brendan Schwartz <bschwartz at ...> writes:
>
>>
>> On Thu, Sep 11, 2008 at 7:58 PM, mike
> <mike503 at gmail.com> wrote:
>> On Thu, Sep 11, 2008 at 3:52 PM, Thomas Witt
> <thomas.witt at infopark.de> wrote:
>> > Please Igor, expand this to regard at least the proxy_pass_header
>> > directive.
>>
>> > In my opinion this special handling of headers makes no sense - when
>> > using a normal upstream you can pass any header you want to. Why don't
>> > to so when using X-Accel-Redirect.
>> I agree. I don't see a need to have limitations on this, myself.
>>
>> I also agree. I would love this feature.
>
>
> Igor, is there any chance, that we'll see this artificial restriction gone in
> nginx soon?
>
> ... thomas
>
>
>





More information about the nginx mailing list