Package com.linecorp.armeria.client.grpc
Class GrpcWebUtil
java.lang.Object
com.linecorp.armeria.client.grpc.GrpcWebUtil
@UnstableApi public final class GrpcWebUtil extends Object
Utilities for working with gRPC-Web.
Note that this class will be removed once a retry ClientInterceptor
is added.
See: https://github.com/line/armeria/issues/2860
-
Method Summary
Modifier and Type Method Description static HttpHeaders
parseTrailers(ClientRequestContext ctx, HttpData response)
Returns a gRPC-Web trailers parsed from the specified response body.
-
Method Details
-
parseTrailers
Returns a gRPC-Web trailers parsed from the specified response body.null
if fail to parse a gRPC-Web trailers.A gRPC-Web response does not contain a separated trailers according to the gRPC-Web spec:
- Trailers must be the last message of the response.
- Trailers may be sent together with response headers, with no message in the body.
AggregatedHttpResponse.headers()
} or parsed fromAggregatedHttpMessage.content()
.This method is useful when
RetryRuleWithContent
needsGrpcHeaderNames.GRPC_STATUS
to decide whether to retry. For example:Clients.builder(grpcServerUri) .decorator(RetryingClient.newDecorator( RetryRuleWithContent.onResponse((ctx, response) -> { return response.aggregate().thenApply(aggregated -> { HttpHeaders trailers = GrpcWebUtil.parseTrailers(ctx, aggregated.content()); // Retry if the 'grpc-status' is not equal to 0. return trailers != null && trailers.getInt(GrpcHeaderNames.GRPC_STATUS) != 0; }); }))) .build(MyGrpcStub.class);
- Throws:
RequestLogAvailabilityException
- if theRequestLogProperty.SCHEME
orRequestLogProperty.RESPONSE_HEADERS
is not available yet from theRequestLog
of the specifiedRequestContext.log()
.
-