Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix HTTPRequestUtils.getRequestHeaderMap #394

Open
wants to merge 4 commits into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,28 @@ public Map<String, List<String>> getRequestHeaderMap() {
if(headerNames != null) {
while (headerNames.hasMoreElements()) {
String name = headerNames.nextElement();
String value = request.getHeader(name);

if(name != null && !name.isEmpty() && value != null) {
List<String> valueList = new ArrayList<String>();
if(headers.containsKey(name)) {
headers.get(name).add(value);
if (name != null && !name.isEmpty()){
Enumeration values = request.getHeaders(name);
if (values != null){
if (headers.get(name) != null){
while (values.hasMoreElements()){
Object value = values.nextElement();
if (value != null){
headers.get(name).add(String.valueOf(value));
}
}
}else{
List<String> list = new ArrayList<>();
while (values.hasMoreElements()){
Object value = values.nextElement();
if (value != null){
list.add(String.valueOf(value));
}

}
headers.put(name, list);
}
}
valueList.add(value);
headers.put(name, valueList);
}
}
}
Expand Down Expand Up @@ -281,6 +294,21 @@ public void detectsGzipAmongOtherEncodings() {
assertTrue(HTTPRequestUtils.getInstance().isGzipped("gzip, deflate"));
}

@Test
public void testgetRequestHeaderMap(){
when(request.getHeaderNames()).thenReturn(new StringTokenizer("accept;language",";"));
when(request.getHeaders("accept")).thenReturn(new StringTokenizer("1;2;3;4",";"));
when(request.getHeaders("language")).thenReturn(new StringTokenizer("zh;ch;ab;de;japan",";"));
Map<String, List<String>> headerMap = HTTPRequestUtils.getInstance().getRequestHeaderMap();
assertEquals(headerMap.get("accept").size(),4);
assertEquals(headerMap.get("accept").get(0),"1");
assertEquals(headerMap.get("accept").get(1),"2");
assertEquals(headerMap.get("accept").get(2),"3");
assertEquals(headerMap.get("accept").get(3),"4");

assertEquals(headerMap.get("language").size(),5);
}

@Test
public void testGetQueryParams() {
when(request.getQueryString()).thenReturn("wsdl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void initZuul() throws Exception, IllegalAccessException, InstantiationException

LOG.info("Starting Groovy Filter file manager");
final AbstractConfiguration config = ConfigurationManager.getConfigInstance();

Thread.sleep(40000);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

final String preFiltersPath = config.getString(ZUUL_FILTER_PRE_PATH);
final String postFiltersPath = config.getString(ZUUL_FILTER_POST_PATH);
final String routingFiltersPath = config.getString(ZUUL_FILTER_ROUTING_PATH);
Expand Down