-
Notifications
You must be signed in to change notification settings - Fork 4k
xds: ignore keep_empty_value and discard header keys on empty mutations #12852
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,24 +67,23 @@ private void applyHeaderUpdates(final Iterable<HeaderValueOption> headerOptions, | |
| private void updateHeader(final HeaderValueOption option, Metadata mutableHeaders) { | ||
| HeaderValue header = option.header(); | ||
| HeaderAppendAction action = option.appendAction(); | ||
| boolean keepEmptyValue = option.keepEmptyValue(); | ||
|
|
||
| if (header.key().endsWith(Metadata.BINARY_HEADER_SUFFIX)) { | ||
| if (header.rawValue().isPresent()) { | ||
| byte[] value = header.rawValue().get().toByteArray(); | ||
| if (value.length > 0 || keepEmptyValue) { | ||
| updateHeader(action, Metadata.Key.of(header.key(), Metadata.BINARY_BYTE_MARSHALLER), | ||
| value, mutableHeaders); | ||
| Metadata.Key<byte[]> key = Metadata.Key.of(header.key(), Metadata.BINARY_BYTE_MARSHALLER); | ||
| updateHeader(action, key, header.rawValue().get().toByteArray(), mutableHeaders); | ||
| if (containsEmpty(key, mutableHeaders)) { | ||
| mutableHeaders.discardAll(key); | ||
| } | ||
| } else { | ||
| logger.fine("Missing binary rawValue for header: " + header.key()); | ||
| } | ||
| } else { | ||
| if (header.value().isPresent()) { | ||
| String value = header.value().get(); | ||
| if (!value.isEmpty() || keepEmptyValue) { | ||
| updateHeader(action, Metadata.Key.of(header.key(), Metadata.ASCII_STRING_MARSHALLER), | ||
| value, mutableHeaders); | ||
| Metadata.Key<String> key = Metadata.Key.of(header.key(), Metadata.ASCII_STRING_MARSHALLER); | ||
| updateHeader(action, key, header.value().get(), mutableHeaders); | ||
| if (containsEmpty(key, mutableHeaders)) { | ||
| mutableHeaders.discardAll(key); | ||
| } | ||
| } else { | ||
| logger.fine("Missing value for header: " + header.key()); | ||
|
|
@@ -119,5 +118,24 @@ private <T> void updateHeader(final HeaderAppendAction action, final Metadata.Ke | |
| logger.fine("Unknown HeaderAppendAction: " + action); | ||
| } | ||
| } | ||
|
|
||
| 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; | ||
| } | ||
|
Comment on lines
+122
to
+139
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
| } | ||
|
|
||
There was a problem hiding this comment.
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.