Class GrpcFrameCodec

java.lang.Object
org.mockserver.grpc.GrpcFrameCodec

public class GrpcFrameCodec extends Object
  • Field Details

    • GZIP_ENCODING

      public static final String GZIP_ENCODING
      The only message encoding MockServer can decode, besides identity.
      See Also:
    • ACCEPT_ENCODING

      public static final String ACCEPT_ENCODING
      Advertised to clients in grpc-accept-encoding so 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_CEILING
      Hard ceiling on the configured message size. This limit is the only bound on the gzip decompression path, which accumulates into a heap ByteArrayOutputStream while comparing against it -- so an unbounded value (say Integer.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 changing maxGrpcMessageSize takes effect without a restart. This is the single definition of the limit -- IncrementalGrpcFrameDecoder reads it from here rather than keeping its own copy, which previously let the two drift.
    • maxMessageSize

      public static int maxMessageSize(Configuration configuration)
      Resolves the limit from a live Configuration when one is available, falling back to the static ConfigurationProperties store.

      Reading only the static store meant Configuration.maxGrpcMessageSize(...) -- and therefore the DTO and PUT /mockserver/config -- silently had no effect, even though all four equivalent forms are documented. The sibling maxRequestBodySize is consumed via the instance, so this restores the established pattern.

    • isSupportedEncoding

      public static boolean isSupportedEncoding(String grpcEncoding)
      Returns true if the requested grpc-encoding is one MockServer can decode. null/empty means the client sent no preference, which is identity.
    • encode

      public static byte[] encode(byte[] message, boolean compress)
    • encode

      public static byte[] encode(byte[] message)
    • decode

      public static List<byte[]> decode(byte[] data)
    • decode

      public static List<byte[]> decode(byte[] data, String grpcEncoding)
      Decodes length-prefixed gRPC frames, honouring the request's grpc-encoding.

      The compressed flag alone does not identify the algorithm -- the grpc-encoding header does. Assuming gzip whenever the flag is set meant a client negotiating deflate or snappy hit a gzip decode failure reported as INTERNAL, instead of the specification's UNIMPLEMENTED telling it to retry with a supported encoding.

      Parameters:
      grpcEncoding - the request's grpc-encoding header value, may be null
    • decode

      public static List<byte[]> decode(byte[] data, String grpcEncoding, Configuration configuration)
      As decode(byte[], String), enforcing the limit from a live Configuration.
    • decodeSingle

      public static byte[] decodeSingle(byte[] data)
    • decodeSingle

      public static byte[] decodeSingle(byte[] data, String grpcEncoding)