I have a client Scala Play app (2.1.x) that calls a local webservice over http. Response is JSON and gzipped when appropriate headers are set:
Client:
val responsePromise = WS.url(url).withHeaders(("Accept-Encoding", "gzip")).get
val response = Await.result(responsePromise, 30 seconds)
val x = GZIPCompression.decompress(response.body.getBytes("UTF-8"))
Server:
On the server I use the filter play.filters.gzip.GzipFilter
for the compressing, from within a(nother) Play app (2.4.x)
Problem:
When receiving the response on the client side, it throws a ZipException: Not in GZIP format
when passing response.body.getBytes("UTF-8")
into the constructor of GZIPInputStream
:
class GZIPCompression {
public static String decompress(...) {
...
byte[] compressed = response.body.getBytes("UTF-8");
new GZIPInputStream(new ByteArrayInputStream(compressed));
...
}
}
(Code from GZIPCompression[https://stackoverflow.com/a/34305182/132396])
It looks like the compressed data doesn't start from the beginning of the response.body
, thus this does not hold true:
compressed[0] == (byte) (GZIPInputStream.GZIP_MAGIC)
Meaning either the payload sent by the server is corrupted or the client code doesn't do the right thing with it.
I read everything on this topic I could find on the web but nothing could provide a solution so far.