Class Metadata.Key<T>
- java.lang.Object
-
- io.grpc.Metadata.Key<T>
-
- Enclosing class:
- Metadata
@Immutable public abstract static class Metadata.Key<T> extends Object
Key for metadata entries. Allows for parsing and serialization of metadata.Valid characters in key names
Only the following ASCII characters are allowed in the names of keys:
- digits:
0-9
- uppercase letters:
A-Z
(normalized to lower) - lowercase letters:
a-z
- special characters:
-_.
This is a strict subset of the HTTP field-name rules. Applications may not send or receive metadata with invalid key names. However, the gRPC library may preserve any metadata received even if it does not conform to the above limitations. Additionally, if metadata contains non conforming field names, they will still be sent. In this way, unknown metadata fields are parsed, serialized and preserved, but never interpreted. They are similar to protobuf unknown fields.
Note this has to be the subset of valid HTTP/2 token characters as defined in RFC7230 Section 3.2.6 and RFC5234 Section B.1
Note that a key is immutable but it may not be deeply immutable, because the key depends on its marshaller, and the marshaller can be mutable though not recommended.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
Returns true if the two objects are both Keys, and their names match (case insensitive).int
hashCode()
String
name()
Returns the normalized name for this key.static <T> Metadata.Key<T>
of(String name, Metadata.AsciiMarshaller<T> marshaller)
Creates a key for an ASCII header.static <T> Metadata.Key<T>
of(String name, Metadata.BinaryMarshaller<T> marshaller)
Creates a key for a binary header.static <T> Metadata.Key<T>
of(String name, Metadata.BinaryStreamMarshaller<T> marshaller)
Creates a key for a binary header, serializing to input streams.String
originalName()
Returns the original name used to create this key.String
toString()
-
-
-
Method Detail
-
of
public static <T> Metadata.Key<T> of(String name, Metadata.BinaryMarshaller<T> marshaller)
Creates a key for a binary header.- Parameters:
name
- Must contain only the valid key characters as defined in the class comment. Must end withMetadata.BINARY_HEADER_SUFFIX
.
-
of
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/6575") public static <T> Metadata.Key<T> of(String name, Metadata.BinaryStreamMarshaller<T> marshaller)
Creates a key for a binary header, serializing to input streams.- Parameters:
name
- Must contain only the valid key characters as defined in the class comment. Must end withMetadata.BINARY_HEADER_SUFFIX
.
-
of
public static <T> Metadata.Key<T> of(String name, Metadata.AsciiMarshaller<T> marshaller)
Creates a key for an ASCII header.- Parameters:
name
- Must contain only the valid key characters as defined in the class comment. Must not end withMetadata.BINARY_HEADER_SUFFIX
-
originalName
public final String originalName()
Returns the original name used to create this key.
-
name
public final String name()
Returns the normalized name for this key.
-
equals
public final boolean equals(Object o)
Returns true if the two objects are both Keys, and their names match (case insensitive).
-
-