Handle Content-Encoding gzip in Annotated Service

161 views Asked by At

I have an annotated service. Some clients POST requests with the content in plaintext. Other clients POST requests gzipped and include the header Content-Encoding: gzip.

The gzipped requests are failing to be decoded as proto values, because they are not unzipped first.

How do I decorate my action so that it selectively gunzips the body based upon the header value?

  @Post("/foo/bar)
  @Consumes("application/x-protobuf")
  @Produces("application/x-protobuf")
  fun setFooBar(
    request: SetFooBarRequest,
    headers: RequestHeaders,
  ): SetFooBarResponse { ... }

fails with Protocol message tag had invalid wire type. (ie this blob is not a proto value), but only for requests where Content-Encoding: gzip

1

There are 1 answers

0
Ikhoon Eom On BEST ANSWER

DecodingService automatically decodes gzip, deflate and brotli by default. You can apply DecodingService using ServerBuilder.decorate(). For example:

Server.builder()
      .annotatedService(new MyProtobufService())
      .decorate(DecodingService.newDecorator()) // 
      .build();