Skip to content
Merged
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 @@ -390,16 +390,17 @@ private Metadata createGrpcMetadata(@Nullable ClientCallContext context, @Nullab
Metadata metadata = new Metadata();

if (context != null && context.getHeaders() != null) {
// Set a2a-version header if present
String versionHeader = context.getHeaders().get(A2AHeaders.A2A_VERSION.toLowerCase());
if (versionHeader != null) {
metadata.put(VERSION_KEY, versionHeader);
}

// Set a2a-extensions header if present
String extensionsHeader = context.getHeaders().get(A2AHeaders.A2A_EXTENSIONS.toLowerCase());
if (extensionsHeader != null) {
metadata.put(EXTENSIONS_KEY, extensionsHeader);
// Set a2a-version and a2a-extensions headers if present, ignoring case
for (Map.Entry<String, String> header : context.getHeaders().entrySet()) {
if (A2AHeaders.A2A_VERSION.equalsIgnoreCase(header.getKey())) {
if (header.getValue() != null) {
metadata.put(VERSION_KEY, header.getValue());
}
} else if (A2AHeaders.A2A_EXTENSIONS.equalsIgnoreCase(header.getKey())) {
if (header.getValue() != null) {
metadata.put(EXTENSIONS_KEY, header.getValue());
}
}
}
Comment on lines +394 to 404
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For improved readability and to leverage modern Java features, you could use a stream to process the headers. This separates the filtering of non-null values from the main logic of identifying and adding the relevant headers to the metadata.

            context.getHeaders().entrySet().stream()
                    .filter(header -> header.getValue() != null)
                    .forEach(header -> {
                        if (A2AHeaders.A2A_VERSION.equalsIgnoreCase(header.getKey())) {
                            metadata.put(VERSION_KEY, header.getValue());
                        } else if (A2AHeaders.A2A_EXTENSIONS.equalsIgnoreCase(header.getKey())) {
                            metadata.put(EXTENSIONS_KEY, header.getValue());
                        }
                    });


// Add other headers as needed in the future
Expand Down
Loading