Fwd: manipulation request headers before proxy_pass

285 views
Skip to first unread message

Yuexiang Zhang

unread,
Dec 19, 2014, 7:26:20 AM12/19/14
to nginx-...@googlegroups.com

---------- Forwarded message ----------

Hi James,

Headers of request is read-only in nginx-clojure , but we can use nginx variable & proxy_set_header to add/remove/update headers before sending them to the remote upstream/host. e.g


set $my_header_value "";

location /testheader {
      handler_type 'java';
      rewrite_handler_name 'test.MyRewriteHandler';
      proxy_set_header x-testHeadr $my_header_value;
      proxy_pass some-upstream-or-host;
}


in the MyRewriteHandler source, we can do 

((NginxJavaRequest)req).setVariable("my_header_value", "test");


If the value is empty string the header will not be passed to the remote server.


Regards.
Xfeep


On Fri, Dec 19, 2014 at 8:02 PM,  james  wrote:
Hi Xfeep,

 i have a small query regarding the header manipulation .

I tried something like 
((JavaLazyHeaderMap) request.get(Constants.HEADERS)).put("x-testHeadr", "test");

to add a few header values from the rewrite handler.

conf file:
  handler_type 'java';
 rewrite_handler_name

from java i implemented  NginxJavaRingHandler


I was getting an error saying

2014-12-19 05:10:15[error]:put request header  not supported now!
java.lang.UnsupportedOperationException: put request header  not supported now!
at nginx.clojure.java.JavaLazyHeaderMap.put(JavaLazyHeaderMap.java:238)


Is there an alternative way of adding or manipulating the headers before sending them to proxy pass.

Thanks you.

Regards,
 James

SVJ

unread,
Jun 16, 2015, 1:53:22 PM6/16/15
to nginx-...@googlegroups.com
whats the difference between

NginxClojureRT.setNGXVariable(((NginxJavaRequest) request).nativeRequest(), "myvar", "NGINX_VAR1");

and

((NginxJavaRequest) request).setVariable("myvar", "NGINX_VAR1"); 

??

Yuexiang Zhang

unread,
Jun 16, 2015, 2:29:21 PM6/16/15
to SVJ, nginx-...@googlegroups.com
Hi, 

They get  same result.

Regards.
Xfeep


--
You received this message because you are subscribed to the Google Groups "Nginx-Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nginx-clojur...@googlegroups.com.
To post to this group, send email to nginx-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nginx-clojure/eb9748c8-31ae-42c6-8472-8ff81fb1b83f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages