Class GrpcTimeout

java.lang.Object
org.mockserver.grpc.GrpcTimeout

public class GrpcTimeout extends Object
Parses the gRPC grpc-timeout request header, which carries the client's deadline for the whole RPC.

Wire format is a positive integer of at most 8 digits followed by a one-character unit:

   Timeout      = "grpc-timeout" TimeoutValue TimeoutUnit
   TimeoutValue = {1..8}Digit
   TimeoutUnit  = "H" / "M" / "S" / "m" / "u" / "n"
 
The units are case-sensitive: Hours, Minutes, Seconds, milliseconds, umicroseconds, nanoseconds. M and m mean very different things (minutes vs milliseconds), which is why this is parsed explicitly rather than with a case-insensitive match.

A server that receives a timeout should cancel the RPC and report grpc-status: 4 DEADLINE_EXCEEDED once it elapses. Before this existed MockServer passed the header through as an ordinary (still matchable) request header but never honoured it, so an expectation whose Delay exceeded the client's deadline left the client to time out locally while MockServer went on writing to an abandoned stream.

  • Field Details

  • Constructor Details

    • GrpcTimeout

      public GrpcTimeout()
  • Method Details

    • parseNanos

      public static Long parseNanos(String value)
      Parses a grpc-timeout value into nanoseconds.
      Parameters:
      value - the raw header value, may be null
      Returns:
      the timeout in nanoseconds, or null if absent or malformed. A malformed value is treated as "no deadline" rather than as an error: refusing the call would be a harsher response than a real server gives, and the header remains visible for matching.
    • parseNanos

      public static Long parseNanos(HttpRequest request)
      Parses the grpc-timeout header from a request's headers into nanoseconds.
      Returns:
      the timeout in nanoseconds, or null if absent or malformed
    • deadlineExceededMessage

      public static String deadlineExceededMessage(long timeoutNanos)
      The grpc-message MockServer reports when a deadline elapses.