'Handle Content-Encoding gzip in Annotated Service
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
Solution 1:[1]
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();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ikhoon Eom |
