@Test public void dupBinHeadersWithComma() { byte[][] http2Headers = new byte[][] { BINARY_BYTES.name().getBytes(US_ASCII), "BaS,e6,,4+,padding==".getBytes(US_ASCII), BINARY_BYTES.name().getBytes(US_ASCII), "more".getBytes(US_ASCII), BINARY_BYTES.name().getBytes(US_ASCII), "".getBytes(US_ASCII)}; byte[][] rawSerialized = TransportFrameUtil.toRawSerializedHeaders(http2Headers); Metadata recoveredHeaders = InternalMetadata.newMetadata(rawSerialized); byte[][] values = Iterables.toArray(recoveredHeaders.getAll(BINARY_BYTES), byte[].class); assertTrue(Arrays.deepEquals( new byte[][] { BaseEncoding.base64().decode("BaS"), BaseEncoding.base64().decode("e6"), BaseEncoding.base64().decode(""), BaseEncoding.base64().decode("4+"), BaseEncoding.base64().decode("padding"), BaseEncoding.base64().decode("more"), BaseEncoding.base64().decode("")}, values)); }
@SuppressWarnings("BetaApi") @CheckReturnValue public static byte[][] toRawSerializedHeaders(byte[][] http2Headers) { for (int i = 0; i < http2Headers.length; i += 2) { byte[] key = http2Headers[i]; byte[] value = http2Headers[i + 1]; if (endsWith(key, binaryHeaderSuffixBytes)) { for (int idx = 0; idx < value.length; idx++) { if (value[idx] == (byte) ',') { return serializeHeadersWithCommasInBin(http2Headers, i); } } byte[] decodedVal = BaseEncoding.base64().decode(new String(value, US_ASCII)); http2Headers[i + 1] = decodedVal; } else { } } return http2Headers; }
TransportFrameUtil { @SuppressWarnings("BetaApi") @CheckReturnValue public static byte[][] toRawSerializedHeaders(byte[][] http2Headers) { for (int i = 0; i < http2Headers.length; i += 2) { byte[] key = http2Headers[i]; byte[] value = http2Headers[i + 1]; if (endsWith(key, binaryHeaderSuffixBytes)) { for (int idx = 0; idx < value.length; idx++) { if (value[idx] == (byte) ',') { return serializeHeadersWithCommasInBin(http2Headers, i); } } byte[] decodedVal = BaseEncoding.base64().decode(new String(value, US_ASCII)); http2Headers[i + 1] = decodedVal; } else { } } return http2Headers; } }
TransportFrameUtil { @SuppressWarnings("BetaApi") @CheckReturnValue public static byte[][] toRawSerializedHeaders(byte[][] http2Headers) { for (int i = 0; i < http2Headers.length; i += 2) { byte[] key = http2Headers[i]; byte[] value = http2Headers[i + 1]; if (endsWith(key, binaryHeaderSuffixBytes)) { for (int idx = 0; idx < value.length; idx++) { if (value[idx] == (byte) ',') { return serializeHeadersWithCommasInBin(http2Headers, i); } } byte[] decodedVal = BaseEncoding.base64().decode(new String(value, US_ASCII)); http2Headers[i + 1] = decodedVal; } else { } } return http2Headers; } private  TransportFrameUtil(); }
TransportFrameUtil { @SuppressWarnings("BetaApi") @CheckReturnValue public static byte[][] toRawSerializedHeaders(byte[][] http2Headers) { for (int i = 0; i < http2Headers.length; i += 2) { byte[] key = http2Headers[i]; byte[] value = http2Headers[i + 1]; if (endsWith(key, binaryHeaderSuffixBytes)) { for (int idx = 0; idx < value.length; idx++) { if (value[idx] == (byte) ',') { return serializeHeadersWithCommasInBin(http2Headers, i); } } byte[] decodedVal = BaseEncoding.base64().decode(new String(value, US_ASCII)); http2Headers[i + 1] = decodedVal; } else { } } return http2Headers; } private  TransportFrameUtil(); @SuppressWarnings("BetaApi") // BaseEncoding is stable in Guava 20.0 static byte[][] toHttp2Headers(Metadata headers); @SuppressWarnings("BetaApi") // BaseEncoding is stable in Guava 20.0 @CheckReturnValue static byte[][] toRawSerializedHeaders(byte[][] http2Headers); }
TransportFrameUtil { @SuppressWarnings("BetaApi") @CheckReturnValue public static byte[][] toRawSerializedHeaders(byte[][] http2Headers) { for (int i = 0; i < http2Headers.length; i += 2) { byte[] key = http2Headers[i]; byte[] value = http2Headers[i + 1]; if (endsWith(key, binaryHeaderSuffixBytes)) { for (int idx = 0; idx < value.length; idx++) { if (value[idx] == (byte) ',') { return serializeHeadersWithCommasInBin(http2Headers, i); } } byte[] decodedVal = BaseEncoding.base64().decode(new String(value, US_ASCII)); http2Headers[i + 1] = decodedVal; } else { } } return http2Headers; } private  TransportFrameUtil(); @SuppressWarnings("BetaApi") // BaseEncoding is stable in Guava 20.0 static byte[][] toHttp2Headers(Metadata headers); @SuppressWarnings("BetaApi") // BaseEncoding is stable in Guava 20.0 @CheckReturnValue static byte[][] toRawSerializedHeaders(byte[][] http2Headers);  }