I am using Unirest in java app for API call. The API server is a spring-boot app with the compression enabled
server.compression.enabled=true
server.compression.mime-types=application/json
server.compression.min-response-size=1
This is my api call
HttpResponse<String> response = Unirest.post(url)
.header("Accept-Encoding", "gzip")
.header("Content-Type", "application/json")
.body(request)
.asString();
However response header "Content-Type" is always "application/json"
Unirest version
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.14.5</version>
</dependency>
I am using it with SSL connection from Spring boot app v.3.3.5.
I tried the same call with curl
curl --request POST --url 'myurl' --header 'Accept-Encoding: gzip' --header 'Content-Type: application/json' --data 'jsonData' -i | less
Response
...
HTTP/1.1 200
vary: accept-encoding
Content-Encoding: gzip
Content-Type: application/json
...
I tried the same API call from Insomnia client
> POST
...
> User-Agent: insomnia/2021.4.1
> Content-Type: application/json
> Accept-Encoding: gzip
Response:
< HTTP/1.1 200
< vary: accept-encoding
< Content-Encoding: gzip
< Content-Type: application/json
...
I also checked request headers in APi server and they all have "Accept-Encoding: gzip". It looks like it doesn't work only with Unirest.
I found the answer. Based on this 2 Unirest issues:
Unirest (precisely Apache Http Client) uncompresses files under the hood and then replaces Content-Encoding: gzip
.
I also tested response length on the server side with Unirest and non-Unirest clients, with and without compression and the sizes are the same.