-
Notifications
You must be signed in to change notification settings - Fork 66
fix: retrieving http headers on request object should be case insenstive #178
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
Conversation
@@ -120,6 +120,11 @@ public Map<String, List<String>> getHeaders() { | |||
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kind of a drive-by comment here. I wrote this code originally and I admit the case-sensitivity aspect didn't occur to me. An alternative fix would be to change this method like this:
return Collections.list(request.getHeaderNames()).stream()
.collect(
toMap(
name -> name,
name -> Collections.list(request.getHeaders(name)),
(a, b) -> b,
() -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER));
That also has the advantage of a predictable iteration order, and it means the getHeaders()
map is also case-insensitive, not just getFirstHeader
.
Regardless of whether you choose this alternative, I think it would be good to remove the .map
step in favour of doing the transformation in .toMap
. Also, even though HttpResponse.getFirstHeader
is presumably called much less often, I think it should also be case-insensitive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for jumping in on this, I like the solution of moving to TreeMap. I've gone ahead and pulled your code snippet into the PR and updated the HttpResponseImpl definitions.
WDYT?
4220728
to
3cc8236
Compare
// and the underlying Writer that response.getWriter() wraps. We could try accessing the | ||
// PrintWriter.out field via reflection, but that sort of access to non-public fields of | ||
// platform classes is now frowned on and may draw warnings or even fail in subsequent | ||
// Unfortunately this means that we get two intermediate objects between the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure these lines needed to be changed?
3cc8236
to
b3df3d9
Compare
Makes the HttpRequest.getFirstHeader operation case insensitive (and offers a slight performance improvement) by using the underlying HttpServletRequest.getHeader on the underlying request object.