I'm trying to generate custom HttpHeader in akka. I've a HashMap of header entries which I need to convert to Iterable. Here's my code:
import akka.http.javadsl.model.HttpHeader;
HashMap<String, String> headersMap = new HashMap<>();
headersMap.put("key1","value1");
return (Iterable<HttpHeader>) headersMap;
//HttpRequest.create().withUri("uri").addHeaders(Iterable<HttpHeader> iterable)
public static Iterable<HttpHeader> convertToRecordHttpHeaders(Map<String, String> headersMap){
return headersMap.entrySet().stream()
.map(x -> new HttpHeader(x.getKey(), x.getValue()))
.collect(Collectors.toList());
}
What's the efficient way to convert the map to HttpHeader and convert it to Iterable as I want to create a HttpRequest in akka.
Solution: Used RawHeader to add headers to request
request.addHeader(RawHeader.create("key","value"));