Skip to content

Commit

Permalink
Merge pull request Netflix#144 from SDFE/1.x
Browse files Browse the repository at this point in the history
replace header with zuul request header, fix multiple header bug
  • Loading branch information
mikeycohen committed Aug 21, 2015
2 parents 85ae0cc + 7885d20 commit 8a29cf4
Showing 1 changed file with 16 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -319,35 +319,37 @@ class ZuulHostRequest extends ZuulFilter {
return true;
}

def Header[] buildZuulRequestHeaders(HttpServletRequest request) {

def headers = new ArrayList()
def Header[] buildZuulRequestHeaders(HttpServletRequest request) {
Map headers = new HashMap()
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String name = (String) headerNames.nextElement();
String value = request.getHeader(name);
if (isValidHeader(name)) headers.add(new BasicHeader(name, value))

final StringBuilder valBuilder = new StringBuilder();
for (final Enumeration vals = request.getHeaders(name); vals.hasMoreElements();) {
valBuilder.append(vals.nextElement());
valBuilder.append(',')
}
valBuilder.setLength(valBuilder.length()-1)

if (isValidHeader(name)) {
headers.put(name.toLowerCase(),new BasicHeader(name, valBuilder.toString()))
}
}

Map zuulRequestHeaders = RequestContext.getCurrentContext().getZuulRequestHeaders();

zuulRequestHeaders.keySet().each {
String name = it.toLowerCase()
BasicHeader h = headers.find { BasicHeader he -> he.name == name }
if (h != null) {
headers.remove(h)
}
headers.add(new BasicHeader((String) it, (String) zuulRequestHeaders[it]))
headers.put(it.toLowerCase(),new BasicHeader((String) it, (String) zuulRequestHeaders[it]))
}

if (RequestContext.currentContext.responseGZipped) {
headers.add(new BasicHeader("accept-encoding", "deflate, gzip"))
headers.put("accept-encoding",new BasicHeader("accept-encoding", "deflate, gzip"))
}
return headers
return headers.values().toArray()
}



String getVerb(HttpServletRequest request) {
String sMethod = request.getMethod();
return sMethod.toUpperCase();
Expand Down

0 comments on commit 8a29cf4

Please sign in to comment.