Package org.mockserver.grpc
Class GrpcTimeout
java.lang.Object
org.mockserver.grpc.GrpcTimeout
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringdeadlineExceededMessage(long timeoutNanos) Thegrpc-messageMockServer reports when a deadline elapses.static LongparseNanos(String value) Parses agrpc-timeoutvalue into nanoseconds.static LongparseNanos(HttpRequest request) Parses thegrpc-timeoutheader from a request's headers into nanoseconds.
-
Field Details
-
GRPC_TIMEOUT_HEADER
- See Also:
-
-
Constructor Details
-
GrpcTimeout
public GrpcTimeout()
-
-
Method Details
-
parseNanos
Parses agrpc-timeoutvalue into nanoseconds.- Parameters:
value- the raw header value, may benull- Returns:
- the timeout in nanoseconds, or
nullif 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
Parses thegrpc-timeoutheader from a request's headers into nanoseconds.- Returns:
- the timeout in nanoseconds, or
nullif absent or malformed
-
deadlineExceededMessage
Thegrpc-messageMockServer reports when a deadline elapses.
-