Skip to content

Remove null empty headers#724

Merged
velo merged 3 commits into
OpenFeign:masterfrom
fmcejudo:remove_null_empty_headers
Jul 6, 2018
Merged

Remove null empty headers#724
velo merged 3 commits into
OpenFeign:masterfrom
fmcejudo:remove_null_empty_headers

Conversation

@fmcejudo

Copy link
Copy Markdown
Contributor

* @see Request#headers()
*/
public Map<String, Collection<String>> headers() {
headers.forEach((key, value) -> value.removeIf(e -> e == null));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't like the idea of modifying the existing map...

may be just filter and create new one?!

…he current map. Supporting with tests as it needs to be LinkedHashMap not to lost the sorting
@velo

velo commented Jul 5, 2018

Copy link
Copy Markdown
Member

@kdavisk6 LGTM, what do you think?

Do you foresee any issues on removing empty headers?


return Collections.unmodifiableMap(
headers.entrySet().stream().filter(h -> h.getValue() != null && !h.getValue().isEmpty())
.collect(toMap(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

just use default toMap... toMap(Entry::getKey, Entry::getValue) no need to handle duplicated keys or map creation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if I do so, it returns the map in any order, with LinkedHashMap it collects them in same order. In fact that was my first approach and it broke tests

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The order of the Map really should not matter, but I don't have a strong opinion on the use of LinkedHashMap. I do agree that there is no need to handle duplicates, that is, unless you want to support that. In that case, I would merge the duplicate key values, since it is acceptable to have more than one value for a header.

@kdavisk6

kdavisk6 commented Jul 5, 2018

Copy link
Copy Markdown
Member

@velo I've added some feedback, I think this is ok to merge.

@velo velo merged commit ed2cef0 into OpenFeign:master Jul 6, 2018
@kdavisk6 kdavisk6 added this to the 10.0 milestone Aug 10, 2018
velo pushed a commit that referenced this pull request Oct 7, 2024
* Creating headers from Request removing those with null or empty values

* Moving back to let the empty strings as valid header

* Returning headers filtering null and empty rather removing them for the current map. Supporting with tests as it needs to be LinkedHashMap not to lost the sorting
velo pushed a commit that referenced this pull request Oct 8, 2024
* Creating headers from Request removing those with null or empty values

* Moving back to let the empty strings as valid header

* Returning headers filtering null and empty rather removing them for the current map. Supporting with tests as it needs to be LinkedHashMap not to lost the sorting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants