Skip to content

xds: ignore keep_empty_value and discard header keys on empty mutations#12852

Open
kannanjgithub wants to merge 1 commit into
grpc:masterfrom
kannanjgithub:empty_header_value_noop
Open

xds: ignore keep_empty_value and discard header keys on empty mutations#12852
kannanjgithub wants to merge 1 commit into
grpc:masterfrom
kannanjgithub:empty_header_value_noop

Conversation

@kannanjgithub

Copy link
Copy Markdown
Contributor

In GrpcService/ext_proc header mutations, we do not support the keep_empty_value field (grpc/proposal@f6d42d6). If any header mutation results in a header containing an empty value (either string or binary), the entire header key is discarded/removed from the metadata.

This change modifies HeaderMutator to apply mutations and discard keys containing empty values.

In GrpcService/ext_proc header mutations, we do not support the
`keep_empty_value` field (grpc/proposal@f6d42d6).
If any header mutation results in a header containing an empty value (either string or binary), the
entire header key is discarded/removed from the metadata.

This chang modifies HeaderMutator to apply mutations and discard keys containing empty values.
@kannanjgithub kannanjgithub requested a review from sauravzg June 10, 2026 05:28
@sauravzg

Copy link
Copy Markdown
Contributor

/gemini review

@sauravzg

Copy link
Copy Markdown
Contributor

/gemini-review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the header mutation logic in HeaderMutator.java to discard headers containing empty values, updating the corresponding test cases in HeaderMutatorTest.java to reflect this change. A review comment suggests that the newly added containsEmpty helper method is redundant and can be safely removed.

Comment on lines +122 to +139
private <T> boolean containsEmpty(Metadata.Key<T> key, Metadata headers) {
Iterable<T> values = headers.getAll(key);
if (values == null) {
return false;
}
for (T val : values) {
if (val instanceof String) {
if (((String) val).isEmpty()) {
return true;
}
} else if (val instanceof byte[]) {
if (((byte[]) val).length == 0) {
return true;
}
}
}
return false;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Since empty mutations are now handled directly in updateHeader without needing to scan the metadata, the containsEmpty helper method is no longer needed and can be safely removed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We might want to investigate the need for this function. I've added a comment here previously grpc/proposal#481 (comment)
about compliance with envoy behavior.

private void updateHeader(final HeaderValueOption option, Metadata mutableHeaders) {
HeaderValue header = option.header();
HeaderAppendAction action = option.appendAction();
boolean keepEmptyValue = option.keepEmptyValue();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should probably delete the config field as well if unused.

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.

2 participants