Custom header in request object

18 views
Skip to first unread message

Vani Gupta

unread,
Dec 6, 2017, 2:25:39 AM12/6/17
to Nginx-Clojure
Hi,

I am creating a proxy server and I need to send a custom header in the request object while poxying request to upstream server. I used Java header filter and tried request.put("test","value") but it was not printed in the list of headers when I printed on upstream server. Can someone guide on how it can be done?

Vani Gupta

unread,
Dec 7, 2017, 2:58:48 AM12/7/17
to Nginx-Clojure
Below is the code. I printed header on the upstream server but GUID is not printed

public class NginxTestHandler implements NginxJavaHeaderFilter {

private static final String COOKIE_NAME = "WORK";

@Override

public Object[] doFilter(int status, Map<String, Object> request, Map<String, Object> responseHeaders) {

ArrayMap<String, Object> responseHeadersMap = new ArrayMap<String, Object>();

System.err.println("before test hand");

responseHeaders.remove("Content-Type");

responseHeaders.put("Content-Type", "text/html");

responseHeaders.put("Xfeep-Header", "Hello2!");

responseHeaders.put("Server", "My-Test-Server");

NginxUtils.setCookies(responseHeadersMap, COOKIE_NAME, "help");

responseHeaders.putAll(responseHeadersMap);

request.put("GUID", "A1234567");

return Constants.PHASE_DONE;

}

}



On Wednesday, December 6, 2017 at 12:25:39 AM UTC-7, Vani Gupta wrote:

Yuexiang Zhang

unread,
Dec 7, 2017, 8:48:30 PM12/7/17
to Vani Gupta, Nginx-Clojure
Hi, Header filter only can be used to change response header.
When you want to change the request header before proxy pass to upstream please try to use rewrite handler and proxy_set_header .

--
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-clojure+unsubscribe@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/67efd05e-af54-47bd-8679-549fb2b662b7%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages