-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes case insensitive headerMap and header toMultimap
Makes all ways to work with headers consistent and comply with the HTTP Headers RFC.
- Loading branch information
Showing
5 changed files
with
56 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.jooby.internal; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import io.jooby.Context; | ||
import io.jooby.ValueNode; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.TreeMap; | ||
|
||
public class HeadersValue extends HashValue implements ValueNode { | ||
|
||
public HeadersValue(final Context ctx) { | ||
super(ctx); | ||
} | ||
|
||
@Override | ||
protected Map<String, ValueNode> hash() { | ||
if (hash == EMPTY) { | ||
hash = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); | ||
} | ||
return hash; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Map<String, String> toMap() { | ||
Map<String, String> map = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); | ||
toMultimap().forEach((k, v) -> map.put(k, v.get(0))); | ||
return map; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public Map<String, List<String>> toMultimap() { | ||
Map<String, List<String>> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); | ||
Set<Map.Entry<String, ValueNode>> entries = hash.entrySet(); | ||
for (Map.Entry<String, ValueNode> entry : entries) { | ||
ValueNode value = entry.getValue(); | ||
result.putAll(value.toMultimap()); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters