I have made a sample application. Even after enabling the request and response compression is not happening.
I am attaching the sample application.
Yml file
server:
port: 8192
servlet:
context-path: /api/demo
compression:
enabled: true
min-response-size: 1024
feign.compression.request.enabled: true
feign.compression.response.enabled: true
feign.client.config.default.loggerLevel: HEADERS
logging.level.com.example.feigndemo.ApiClient: DEBUG
eureka:
client:
enabled: false
api-client:
ribbon:
listOfServers: localhost:8192
The response headers does not contain gzip
when I hit the request from browser gzip happens
Server Call: http://localhost:8192/api/demo/feign/1
To Trigger feign call: feigndemo.zip
http://localhost:8192/api/demo/1
Can you please help.
Comment From: a601942905git
You should try the interface for passing body data. Then set the log feign: client: config: default: loggerLevel: FULL
Comment From: patan12
@a601942905git
This just enables the logging. Still I do not response headers that content is compressed
Comment From: a601942905git
When I tested, only the request has compression, and response does not.
Comment From: patan12
@a601942905git Same with me as well.
Comment From: ryanjbaxter
How are you making the request? If I do curl -v -H "Accept-Encoding: gzip" http://localhost:8192/api/demo/1 in the response headers I see
< HTTP/1.1 200
< vary: accept-encoding
< Content-Encoding: gzip
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
< Date: Mon, 16 Sep 2019 18:36:43 GMT
Comment From: patan12
@ryanjbaxter
Sorry, I clubbed both server and client in one application. It might have caused some confusion
I am trying to simulate the below situation.
One Application invokes server through feign. Server has gzip compression enabled. And when feign compression is enabled, I expect the request and response to be compressed/uncompressed.
Here I have clubbed the server and client in the same application.
I invoke the http://localhost:8192/api/demo/1 from outside and it internally makes feign call to this http://localhost:8192/api/demo/feign/1
As I have enabled the compression at feign level, I expect the feign request shall pass gzip headers and response should contain gzip headers.
I notice two issues here
- Feign adds two headers Accept-Encoding: deflate and Accept-Encoding: gzip. Though it is legally accepted, but spring boot has some issue. To make it work with spring boot there shall be only one header like this Accept-Encoding: deflate,gzip
ref issue: https://github.com/spring-projects/spring-boot/issues/18176
- Second issue is that, I manually added Accept-Encoding: deflate,gzip to request, but feign was unable to compress response.
Let me know for any information
Comment From: ryanjbaxter
This still seems to be working as expected to me. Client makes a request without "Accept-Encoding: gzip
For example
curl -v http://localhost:8192/api/demo/1
Feign will add the Accept-Encoding: deflate,gzip header to the request made by the feign client. The server will receive those headers in the request and if compression is enabled reply back with a compressed response. However since the client (cURL) did not specify the headers the server should not return compressed data back to cURL in this case.
Feign adds two headers Accept-Encoding: deflate and Accept-Encoding: gzip. Though it is legally accepted, but spring boot has some issue. To make it work with spring boot there shall be only one header like this Accept-Encoding: deflate,gzip
When I log the headers that come in to /feign/{id} I see
headers=[accept-encoding:"deflate", "gzip", accept:"*/*", user-agent:"Java/1.8.0_91", host:"localhost:8192", connection:"keep-alive"]. So it does appear that they are being sent correctly.
Comment From: patan12
@ryanjbaxter Sorry, I could not see response headers.
Am I missing something.
Here are the logs.
curl http://localhost:8192/api/demo/1
I can see these logs which denotes that 1. Request contains two separate Accept-Encoding Headers 2. Response headers does not have gzip encoding
[nio-8192-exec-7] com.example.feigndemo.ApiClient : [ApiClient#getId] ---> GET http://api-client/api/demo/feign/1 HTTP/1.1
[nio-8192-exec-7] com.example.feigndemo.ApiClient : [ApiClient#getId] Accept-Encoding: deflate
[nio-8192-exec-7] com.example.feigndemo.ApiClient : [ApiClient#getId] Accept-Encoding: gzip
[nio-8192-exec-7] com.example.feigndemo.ApiClient : [ApiClient#getId] ---> END HTTP (0-byte body)
[nio-8192-exec-7] com.example.feigndemo.ApiClient : [ApiClient#getId] <--- HTTP/1.1 200 (3ms)
[nio-8192-exec-7] com.example.feigndemo.ApiClient : [ApiClient#getId] content-length: 12144
[nio-8192-exec-7] com.example.feigndemo.ApiClient : [ApiClient#getId] content-type: application/json;charset=UTF-8
[nio-8192-exec-7] com.example.feigndemo.ApiClient : [ApiClient#getId] date: Thu, 19 Sep 2019 04:16:03 GMT
[nio-8192-exec-7] com.example.feigndemo.ApiClient : [ApiClient#getId] vary: accept-encoding
[nio-8192-exec-7] com.example.feigndemo.ApiClient : [ApiClient#getId] <--- END HTTP (12144-byte body)
Comment From: ryanjbaxter
The fact that you see
2019-09-19 09:52:19.604 DEBUG 71953 --- [nio-8192-exec-1] com.example.feigndemo.ApiClient : [ApiClient#getId] Accept-Encoding: deflate
2019-09-19 09:52:21.291 DEBUG 71953 --- [nio-8192-exec-1] com.example.feigndemo.ApiClient : [ApiClient#getId] Accept-Encoding: gzip
in the logs is just a side effect of how Feign is logging headers. Each value of each header will be printed out individually on its own line, see
https://github.com/OpenFeign/feign/blob/master/core/src/main/java/feign/Logger.java#L51
Add the following code to your app
@Configuration
public class RequestLoggingFilterConfig {
@Bean
public CommonsRequestLoggingFilter logFilter() {
CommonsRequestLoggingFilter filter
= new CommonsRequestLoggingFilter();
filter.setIncludeQueryString(true);
filter.setIncludePayload(true);
filter.setMaxPayloadLength(10000);
filter.setIncludeHeaders(true);
filter.setAfterMessagePrefix("REQUEST DATA : ");
return filter;
}
}
And then add log.level.org.springframework.web.filter.CommonsRequestLoggingFilter: DEBUG to application.yml and you will see the headers as they actually appear in the request.
Response headers does not have gzip encoding
I am asserting the the response headers should not have gzip encoding because you are not setting the Accept-Encoding header when making the cURL request. The server is honoring what the client requested.
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.