Class GrpcStatusMapper
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringResponse header advertising the encodings the server can decode, so a client whose preferred encoding is unsupported knows what to retry with.static final Stringstatic final StringRequest header naming the message encoding the client used, e.g.static final Stringstatic final Stringstatic final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfromCode(int code) fromHttpStatus(int httpStatus) fromHttpTransportStatus(int httpStatus) Maps an HTTP response status onto the gRPC status a client should observe, per the "HTTP-Status → Status code" table in the gRPC-over-HTTP/2 protocol specification.static booleanisGrpcContentType(String contentType) static StringpercentDecodeMessage(String message) Percent-decodes agrpc-messagereceived from an upstream gRPC server, reversingpercentEncodeMessage(String).static StringpercentEncodeMessage(String message) Percent-encodes agrpc-messagevalue for transmission, per the gRPC wire specification'sPercent-Encodedproduction.static StringstripControlCharacters(String value) Removes C0 control characters (and DEL) from a value decoded from an untrusted source.
-
Field Details
-
GRPC_STATUS_HEADER
- See Also:
-
GRPC_MESSAGE_HEADER
- See Also:
-
GRPC_STATUS_NAME_HEADER
- See Also:
-
GRPC_CONTENT_TYPE
- See Also:
-
GRPC_ENCODING_HEADER
Request header naming the message encoding the client used, e.g.gzip. The frame's compressed flag says only THAT a message is compressed; this says how.- See Also:
-
GRPC_ACCEPT_ENCODING_HEADER
Response header advertising the encodings the server can decode, so a client whose preferred encoding is unsupported knows what to retry with.- See Also:
-
-
Constructor Details
-
GrpcStatusMapper
public GrpcStatusMapper()
-
-
Method Details
-
fromCode
-
fromName
-
fromHttpStatus
-
fromHttpTransportStatus
Maps an HTTP response status onto the gRPC status a client should observe, per the "HTTP-Status → Status code" table in the gRPC-over-HTTP/2 protocol specification.This is deliberately not
fromHttpStatus(int). That method inverts the gRPC → HTTP mapping carried onGrpcStatusMapper.GrpcStatusCode(so 404 →NOT_FOUND, the status whose canonical HTTP rendering is 404). This method implements the separate, spec-defined mapping used when a gRPC call fails at the HTTP transport level and nogrpc-statusis available — where 404 means "the server does not implement this method" and therefore maps toUNIMPLEMENTED. -
percentEncodeMessage
Percent-encodes agrpc-messagevalue for transmission, per the gRPC wire specification'sPercent-Encodedproduction.The spec defines the value as ASCII only:
Percent-Encoded = 1*(Percent-Byte-Unescaped / Percent-Byte-Escaped) Percent-Byte-Unescaped = %x20-24 / %x26-7E ; space..'$' and '&'..'~' Percent-Byte-Escaped = "%" 2HEXDIG
so every byte outside0x20-0x7E, plus%(0x25) itself, is escaped as%XXover the value's UTF-8 bytes. Clients percent-decode on receipt.This must be applied at every emission site. Writing the raw string is wrong even for ordinary input:
"quota 50% exceeded"— the client decodes%20(from "50% e") into a space, silently corrupting a plain-ASCII message. No exotic characters required."paiement refusé"— on HTTP/1.1 and HTTP/2 Netty'sAsciiStringconversion byte-castschar & 0xFF, so the client receives ISO-8859-1 bytes and grpc-java's UTF-8 decode produces mojibake. In the gRPC-Web trailer frame, which is written asUS_ASCII, every non-ASCII character becomes a literal?— silent data loss."denied\r\ngrpc-status: 0"— the gRPC-Web trailer frame is a CRLF-delimited block, so an unescaped CRLF injects a secondgrpc-statusline and can turn an error into a success. Encoding CR and LF as%0D/%0Acloses this.
- Parameters:
message- the raw message, may benull- Returns:
- the percent-encoded message, or
nullifmessagewasnull
-
percentDecodeMessage
Percent-decodes agrpc-messagereceived from an upstream gRPC server, reversingpercentEncodeMessage(String).Lenient, matching grpc-java: a
%that is not followed by two hex digits is passed through literally rather than treated as an error, so a server that (like MockServer before this was implemented) emits an unencoded message is not made worse.- Parameters:
message- the percent-encoded message, may benull- Returns:
- the decoded message, or
nullifmessagewasnull
-
stripControlCharacters
Removes C0 control characters (and DEL) from a value decoded from an untrusted source.Percent-decoding an upstream
grpc-messagecan produce real NUL or CRLF bytes from%00/%0D%0A. That value flows intoLogEntry, the persisted log, verifications and the dashboard, so a hostile upstream -- exactly the party the proxy use case treats as untrusted -- could forge log lines. The printable text is preserved. -
isGrpcContentType
-