Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
Expand All @@ -55,10 +53,23 @@ private CloudEventHttpUtils() {
* @return a {@link MessageReader} representing the {@link CloudEvent}
* @throws CloudEventRWException if something goes wrong while resolving the {@link SpecVersion} or if the message has unknown encoding
*/
@SuppressWarnings("unchecked")
public static MessageReader toReader(HttpHeaders headers, Supplier<byte[]> body) throws CloudEventRWException {
Map<String, List<String>> headersMap = new HashMap<>();
headers.forEach((key, values) -> headersMap.put(key, new ArrayList<>(values)));
return HttpMessageFactory.createReaderFromMultimap(headersMap, body.get());
MessageReader reader;

// Temporary compatibility workaround for Spring Framework 7 HttpHeaders changes.
// Remove this branch and use the standard path once native Spring 7 support is released.
if (headers instanceof Map<?, ?>) {
reader = HttpMessageFactory.createReaderFromMultimap((Map<String, List<String>>) headers, body.get());
} else {
// Spring 7+ no longer guarantees HttpHeaders implements Map, so use the header visitor API.
reader = HttpMessageFactory.createReader(
processHeader -> headers.forEach(
(key, values) -> values.forEach(value -> processHeader.accept(key, value))),
body.get());
}

return reader;
}

/**
Expand Down
Loading