Package org.mockserver.grpc
Class GrpcFrameCodec
java.lang.Object
org.mockserver.grpc.GrpcFrameCodec
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringAdvertised to clients ingrpc-accept-encodingso a client whose preferred encoding is unsupported knows what to retry with.static final StringThe only message encoding MockServer can decode, besidesidentity.static final intHard ceiling on the configured message size. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic List<byte[]>decode(byte[] data) static List<byte[]>Decodes length-prefixed gRPC frames, honouring the request'sgrpc-encoding.static List<byte[]>decode(byte[] data, String grpcEncoding, Configuration configuration) Asdecode(byte[], String), enforcing the limit from a liveConfiguration.static byte[]decodeSingle(byte[] data) static byte[]decodeSingle(byte[] data, String grpcEncoding) static byte[]encode(byte[] message) static byte[]encode(byte[] message, boolean compress) static booleanisSupportedEncoding(String grpcEncoding) Returnstrueif the requestedgrpc-encodingis one MockServer can decode.static intThe maximum decoded message size, resolved from configuration on each call so a test or embedded user changingmaxGrpcMessageSizetakes effect without a restart.static intmaxMessageSize(Configuration configuration) Resolves the limit from a liveConfigurationwhen one is available, falling back to the staticConfigurationPropertiesstore.
-
Field Details
-
GZIP_ENCODING
The only message encoding MockServer can decode, besidesidentity.- See Also:
-
ACCEPT_ENCODING
Advertised to clients ingrpc-accept-encodingso a client whose preferred encoding is unsupported knows what to retry with.- See Also:
-
MAX_MESSAGE_SIZE_CEILING
public static final int MAX_MESSAGE_SIZE_CEILINGHard ceiling on the configured message size. This limit is the only bound on the gzip decompression path, which accumulates into a heapByteArrayOutputStreamwhile comparing against it -- so an unbounded value (sayInteger.MAX_VALUE) would let a few KB of gzip drive a multi-GB allocation. 256 MiB is far above any legitimate gRPC message and still keeps the decompression bomb capped.- See Also:
-
-
Constructor Details
-
GrpcFrameCodec
public GrpcFrameCodec()
-
-
Method Details
-
maxMessageSize
public static int maxMessageSize()The maximum decoded message size, resolved from configuration on each call so a test or embedded user changingmaxGrpcMessageSizetakes effect without a restart. This is the single definition of the limit --IncrementalGrpcFrameDecoderreads it from here rather than keeping its own copy, which previously let the two drift. -
maxMessageSize
Resolves the limit from a liveConfigurationwhen one is available, falling back to the staticConfigurationPropertiesstore.Reading only the static store meant
Configuration.maxGrpcMessageSize(...)-- and therefore the DTO andPUT /mockserver/config-- silently had no effect, even though all four equivalent forms are documented. The siblingmaxRequestBodySizeis consumed via the instance, so this restores the established pattern. -
isSupportedEncoding
Returnstrueif the requestedgrpc-encodingis one MockServer can decode.null/empty means the client sent no preference, which isidentity. -
encode
public static byte[] encode(byte[] message, boolean compress) -
encode
public static byte[] encode(byte[] message) -
decode
-
decode
Decodes length-prefixed gRPC frames, honouring the request'sgrpc-encoding.The compressed flag alone does not identify the algorithm -- the
grpc-encodingheader does. Assuming gzip whenever the flag is set meant a client negotiatingdeflateorsnappyhit a gzip decode failure reported asINTERNAL, instead of the specification'sUNIMPLEMENTEDtelling it to retry with a supported encoding.- Parameters:
grpcEncoding- the request'sgrpc-encodingheader value, may benull
-
decode
Asdecode(byte[], String), enforcing the limit from a liveConfiguration. -
decodeSingle
public static byte[] decodeSingle(byte[] data) -
decodeSingle
-