-
Notifications
You must be signed in to change notification settings - Fork 121
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
Added feature to add custom headers to Service #176
Conversation
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 so much for the contribution @BalasubramanyamEvani - I just had one request to simplify the logic since I believe we're already accounting for the required headers not being overwritten -- I appreciate you going out of the way to prevent these from colliding though,
*/ | ||
public void setCustomHeaders(Map<String, String> headers) { | ||
if (Objects.nonNull(headers) && !headers.isEmpty()) { | ||
Map<String, String> fitleredCustomHeaders = headers.entrySet() |
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.
I think we can remove this logic and the filtertHttpHeaderKeys
above since the custom header values are only added if the header does not already exist down on line 486:
if (!header.containsKey(key)) {
cn.setRequestProperty(key, 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.
Yes, sure that makes sense. Also, I was thinking about whether the customHeaders map needs to be cleared out before populating it if it's not empty?
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.
Oh good call that makes, although if we're not filtering I think a simple reassignment would suffice? e.g.
if (Objects.nonNull(headers)) {
customHeaders = headers;
}
What do you think?
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.
That would cover a case where someone needed to clear the customHeaders that were already set (I can't think of a use case for that, but potentially useful)
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.
Yes, I think a reassignment should suffice. I have made the necessary changes. Please check.
References to other Issues or PRs
Ref #169
Brief description of what is fixed or changed
Other comments
Rather than merging the custom map with the default one, I created a new protected variable to store the custom map
values. Please let me know if this is correct or not.