Skip to content

Commit e16289a

Browse files
address more comments
1 parent 7012623 commit e16289a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

core/src/main/java/io/grpc/InternalMetadata.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public interface TrustedAsciiMarshaller<T> {
6161

6262
/**
6363
* Parse a serialized metadata value from an ASCII string.
64+
*
6465
* @param serialized value of metadata to parse
6566
* @return a parsed instance of type T
6667
*/

core/src/main/java/io/grpc/Metadata.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ private AsciiKey(String name, AsciiMarshaller<T> marshaller) {
605605
super(name);
606606
Preconditions.checkArgument(
607607
!name.endsWith(BINARY_HEADER_SUFFIX),
608-
"ASCII header is named %s. It must not end with %s",
608+
"ASCII header is named %s. Only binary headers may end with %s",
609609
name, BINARY_HEADER_SUFFIX);
610610
this.marshaller = Preconditions.checkNotNull(marshaller, "marshaller");
611611
}
@@ -631,7 +631,7 @@ private TrustedAsciiKey(String name, TrustedAsciiMarshaller<T> marshaller) {
631631
super(name);
632632
Preconditions.checkArgument(
633633
!name.endsWith(BINARY_HEADER_SUFFIX),
634-
"ASCII header is named %s. It must not end with %s",
634+
"ASCII header is named %s. Only binary headers may end with %s",
635635
name, BINARY_HEADER_SUFFIX);
636636
this.marshaller = Preconditions.checkNotNull(marshaller, "marshaller");
637637
}

core/src/main/java/io/grpc/Status.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,13 +592,17 @@ public byte[] toAsciiString(String value) {
592592
for (int i = 0; i < valueBytes.length; i++) {
593593
byte b = valueBytes[i];
594594
// If there are only non escaping characters, skip the slow path.
595-
if (b < ' ' || b >= '~' || b == '%') {
595+
if (isEscapingChar(b)) {
596596
return toAsciiStringSlow(valueBytes, i);
597597
}
598598
}
599599
return valueBytes;
600600
}
601601

602+
private static boolean isEscapingChar(byte b) {
603+
return b < ' ' || b >= '~' || b == '%';
604+
}
605+
602606
/**
603607
* @param valueBytes the UTF-8 bytes
604608
* @param ri The reader index, pointed at the first byte that needs escaping.
@@ -613,7 +617,7 @@ private static byte[] toAsciiStringSlow(byte[] valueBytes, int ri) {
613617
for (; ri < valueBytes.length; ri++) {
614618
byte b = valueBytes[ri];
615619
// Manually implement URL encoding, per the gRPC spec.
616-
if (b < ' ' || b >= '~' || b == '%') {
620+
if (isEscapingChar(b)) {
617621
escapedBytes[wi] = '%';
618622
escapedBytes[wi + 1] = HEX[(b >> 4) & 0xF];
619623
escapedBytes[wi + 2] = HEX[b & 0xF];

0 commit comments

Comments
 (0)