core,netty,testing: Support dup headers joined with commas#5020
Merged
Conversation
ejona86
reviewed
Nov 1, 2018
| * metadata marshallers. It decodes the Base64-encoded binary headers. This function modifies | ||
| * the headers in place. By modifying the input array. | ||
| * | ||
| * <p>Warning: it may mutate the content of the argument. |
Member
There was a problem hiding this comment.
This is a bit confusing, because it only modifies the array, not the byte[]. Would it be better to take the last two sentences of the first paragraph and make it the warning instead? I don't want this method to modify the byte[]s, only the byte[][].
| byte[][] newHttp2Headers = new byte[http2Headers.length + dupHeaders.size()][]; | ||
| System.arraycopy(http2Headers, 0, newHttp2Headers, 0, http2Headers.length); | ||
| System.arraycopy( | ||
| dupHeaders.toArray(new byte[0][]), 0, newHttp2Headers, http2Headers.length, |
Member
There was a problem hiding this comment.
This would reorder headers improperly. Consider:
key-bin: value1,value2
key-bin: value3
| valueBytes = BaseEncoding.base64().decode(curVal); | ||
| startPos = indexOfComma + 1; | ||
| } | ||
| if (namesAndValuesIdx == namesAndValues.length) { |
Member
There was a problem hiding this comment.
It's hard to see the flow now, especially for ascii values. Could the actual adding to the array be moved into a private method, like add0(byte[] name, byte[] value, AsciiString valueStr)? That would let you use the loop only for binary values.
| assertEquals( | ||
| Lists.newArrayList(serverHeadersCopy.getAll(asciiKey)), | ||
| Lists.newArrayList(headers.getAll(asciiKey))); | ||
| assertAsciiMetadataValuesEqual(serverHeadersCopy.getAll(asciiKey),headers.getAll(asciiKey)); |
Contributor
Author
|
PTALA |
ejona86
approved these changes
Nov 1, 2018
| continue; | ||
| } | ||
| byte[] decodedVal = | ||
| BaseEncoding.base64().decode(new String(value, prevIdx, idx - prevIdx, US_ASCII)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Following the spec on duplicate header names:
Custom-Metadata header order is not guaranteed to be preserved except for values with duplicate header names. Duplicate header names may have their values joined with "," as the delimiter and be considered semantically equivalent. Implementations must split Binary-Headers on "," before decoding the Base64-encoded values.