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

Making response headers access case insensitive #217

Open
wants to merge 2 commits into
base: master
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.flipkart.poseidon</groupId>
<artifactId>poseidon</artifactId>
<version>5.14.1</version>
<version>5.14.2-SNAPSHOT</version>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you make it a release version, and update all files with this version?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, will change it to 5.14.2 but before that you don't need to test anything with snapshot version? Also what all files need to be changed?


<name>Poseidon</name>
<description>A platform to build API applications that have to aggregate data from distributed services in an efficient way</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected Boolean initialValue() {
private static final ThreadLocal<Boolean> isDebug = ThreadLocal.withInitial(() -> false);

private static final ThreadLocal<Map<String, List<ServiceDebug>>> debugResponses = ThreadLocal.withInitial(ConcurrentHashMap::new);
private static final ThreadLocal<Map<String, Queue<String>>> collectedHeaders = ThreadLocal.withInitial(HashMap::new);
private static final ThreadLocal<Map<String, Queue<String>>> collectedHeaders = ThreadLocal.withInitial(() -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER));

/**
* initialize an empty service context, it will cleanup previous value of the threadlocal if used in a threadpool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
* Created by venkata.lakshmi on 30/03/15.
Expand All @@ -35,12 +36,14 @@ public ServiceResponse() {}
public ServiceResponse(T data, Map<String, String> headers) {
this.isSuccess = true;
this.dataList.add(data);
this.headers = headers;
this.headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
headers.forEach((k,v) -> this.headers.put(k,v));
}

public ServiceResponse(ServiceClientException e, Map<String, String> headers) {
this.exception = e;
this.headers = headers;
this.headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
headers.forEach((k,v) -> this.headers.put(k,v));
}

public void addData(List<T> data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public ServiceResponseDecoder(ObjectMapper objectMapper, Logger logger, Map<Stri
}

private Map<String, String> getHeaders(HttpResponse httpResponse) {
Map<String, String> headers = new HashMap<>();
Map<String, String> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
Header[] responseHeaders = httpResponse.getAllHeaders();
if (responseHeaders == null || responseHeaders.length == 0) {
return headers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,14 @@ public void testGetException() throws Exception {
assertTrue(response.getDataList().isEmpty());
}

@Test
public void testCaseInsensitiveGetHeader() throws Exception {
ServiceResponse<String> response = new ServiceResponse<>("string", new HashMap<String, String>() {{
put("heAder1", "value1");
}});
assertEquals("value1", response.getHeaders().get("Header1"));
assertEquals("value1", response.getHeaders().get("header1"));
assertEquals("value1", response.getHeaders().get("hEader1"));
}

}