I compressed my JSON Headers like following :
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPOutputStream gzip = new GZIPOutputStream( out );
gzip.write( responseBody.encodePrettily().getBytes( "UTF-8" ) );
gzip.close();
byte[] bytes = out.toByteArray();
String response = Base64.getEncoder().encodeToString( bytes );
And I send this response from the server. On any browser, the response is automatically unzipped and the json data is retrieved. But when sending a GET request on Postman, Insomnia or RestClient (Mozilla Addon), I get the encoded gzip instead of the json data:
H4sIAAAAAAAAAM2POwvCMBSF90L/wyVzB9tmcnZxcLFuIiE0VwikD/IQpOS/20RL1cGt0vWcw/3uN6QJANFonLIE...
How can I make get it unzipped ? I tried with several Rest Clients and none of them unzips it like a browser does.
I found nowhere an answer to this and I'm starting feeling hopeless.
Issue was solved ! Actually it was not necessary to compress the responses manually like I have shown in my question because we're using Vert.X.
Vert.X provides a clever Option to be set in HttpServerOptions in order to do the compression automatically whenever it is possible (i.e. client is supporting compression). Postman and any other REST Client (i.e. browser or whatever) gets the zipped response and automatically unzip it !
I wasted a lot of time but at least learnt something useful. That's why I wanted to share it with you.
If you're using Vert.X, this line of code will do the work for you :
HttpServerOptions options = new HttpServerOptions().setCompressionSupported( true );
Then simply use this HttpServerOptions instance when creating your HttpServer :
HttpServer server = vertx.createHttpServer( options );
PS: You can verify that the compression really happened when you check the response headers returned by your client. You'll find content-encoding : gzip
.