spring-cloud / spring-cloud/spring-cloud-openfeign
Configuration `compression.request.content-encoding-types` ignored when compression is applied
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.3k
- Forks
- 838
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 13
Description
Describe the bug
The configuration spring.cloud.openfeign.compression.request.content-encoding-types is not being considered when compression is applied.
Sample
-
Generate a project at https://start.spring.io including
lombokandOpenFeign(direct link here). -
Include a client in
pom.xml:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>
- Include this in
application.properties:
spring.cloud.openfeign.compression.response.enabled=true
spring.cloud.openfeign.compression.request.content-encoding-types=gzip
spring.cloud.openfeign.client.config.default.request-interceptors=com.example.demo.DemoApplication.MyInterceptor
- Replace the code on
DemoApplication.java:
@EnableFeignClients
@SpringBootApplication
@RequiredArgsConstructor
public class DemoApplication implements CommandLineRunner {
// Only actual necessary code that matters: the request interceptor
public static class MyInterceptor implements RequestInterceptor {
@Setter
private Optional<FeignClientEncodingProperties> properties;
@Override
public void apply(RequestTemplate template) {
final var encodingAppliedRequest = template.headers().get(HttpEncoding.ACCEPT_ENCODING_HEADER);
final var encodingDesiredRequest = properties.map(e -> List.of(e.getContentEncodingTypes())).orElse(List.of());
System.out.println("Encoding in use: " + encodingAppliedRequest);
System.out.println("Encoding desired: " + encodingDesiredRequest);
}
}
// All other code to make things work
private final GithubClient client;
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
client.getIssues();
}
@RequiredArgsConstructor
public static class MyCapability implements Capability {
private final Optional<FeignClientEncodingProperties> properties;
@Override
public RequestInterceptor enrich(RequestInterceptor requestInterceptor) {
if (requestInterceptor instanceof MyInterceptor myInterceptor)
myInterceptor.setProperties(properties);
return requestInterceptor;
}
}
}
@Configuration
class FeignConfiguration {
@Bean
Client client() {
return new ApacheHttpClient();
}
@Bean
Capability feignOAuthTokenCapability(Optional<FeignClientEncodingProperties> properties) {
return new DemoApplication.MyCapability(properties);
}
}
@FeignClient(name = "github", url = "https://github.com/spring-cloud/spring-cloud-openfeign")
interface GithubClient {
@GetMapping("/issues")
String getIssues();
}
Results
The terminal shows:
Encoding in use: [gzip, deflate]
Encoding desired: [gzip]
The expected results should be:
Encoding in use: [gzip]
Encoding desired: [gzip]
Testing
- You can also test replacing
DemoApplicationTests.javawith the code below:
@SpringBootTest
@ExtendWith(MockitoExtension.class)
class DemoApplicationTests {
@Autowired
private FeignClientEncodingProperties properties;
@Autowired
private FeignAcceptGzipEncodingInterceptor interceptor;
@Test
void terstInterceptorContainsEncodingFromProperties() {
final var encodingApplied = new AtomicReference<>(List.<String>of());
final var template = mock(RequestTemplate.class);
when(template.header(eq(HttpEncoding.ACCEPT_ENCODING_HEADER), any(String[].class))).thenAnswer(invocation -> {
encodingApplied.set(List.of((String[]) invocation.getRawArguments()[1]));
return null;
});
interceptor.apply(template);
final var encodingFromProperties = List.of(properties.getContentEncodingTypes());
assertEquals(encodingFromProperties.toString(), encodingApplied.get().toString());
}
}
Versions
- Spring Boot 3.5.5
- Spring Cloud OpenFeign 4.3.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating FeignAcceptGzipEncodingInterceptor, FeignClientEncodingProperties, and the interceptor test shown in DemoApplicationTests.java. Run the focused test and compare the configured content-encoding types with the headers applied to the RequestTemplate. Done means the applied encoding list matches the configured values, including the gzip-only example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100