Skip to content

core,netty,testing: Support dup headers joined with commas#5020

Merged
dapengzhang0 merged 5 commits into
grpc:masterfrom
dapengzhang0:dupheaders
Nov 1, 2018
Merged

core,netty,testing: Support dup headers joined with commas#5020
dapengzhang0 merged 5 commits into
grpc:masterfrom
dapengzhang0:dupheaders

Conversation

@dapengzhang0

Copy link
Copy Markdown
Contributor

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.

* 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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,

@ejona86 ejona86 Nov 1, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add space after comma.

@dapengzhang0

Copy link
Copy Markdown
Contributor Author

PTALA

continue;
}
byte[] decodedVal =
BaseEncoding.base64().decode(new String(value, prevIdx, idx - prevIdx, US_ASCII));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indent two more spaces.

@dapengzhang0 dapengzhang0 merged commit 85b244b into grpc:master Nov 1, 2018
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 30, 2019
@dapengzhang0 dapengzhang0 deleted the dupheaders branch June 1, 2019 20:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants