Forked from jmnarloch/AcceptGzipEncodingFeignRequestInterceptor.java
Created
April 12, 2016 06:58
-
-
Save ambalashov/e10d34b0f8c5d72d399ef61414d1876c to your computer and use it in GitHub Desktop.
Feign content encoding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AcceptGzipEncodingFeignRequestInterceptor implements RequestInterceptor { | |
| private static final String ACCEPT_ENCODING_HEADER = "Accept-Encoding"; | |
| private static final String GZIP_ENCODING = "gzip"; | |
| private static final String DEFLATE_ENCODING = "deflate"; | |
| @Override | |
| public void apply(RequestTemplate template) { | |
| if(!template.headers().containsKey(ACCEPT_ENCODING_HEADER)) { | |
| template.header(ACCEPT_ENCODING_HEADER, GZIP_ENCODING, DEFLATE_ENCODING); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Import(FeignAcceptGzipEncodingConfiguration.class) | |
| @Inherited | |
| @Target(ElementType.TYPE) | |
| @Retention(RetentionPolicy.RUNTIME) | |
| @Documented | |
| public @interface EnableFeignAcceptGzipEncoding { | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Configuration | |
| public class FeignAcceptGzipEncodingConfiguration { | |
| @Bean | |
| public RequestInterceptor acceptGzipEncodingFeignRequestInterceptor() { | |
| return new AcceptGzipEncodingFeignRequestInterceptor(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Configuration | |
| @ConditionalOnClass({Feign.class}) | |
| public class FeignApacheHttpClientAutoConfiguration { | |
| @Configuration | |
| @ConditionalOnClass(ApacheHttpClient.class) | |
| protected static class HttpClientConfiguration { | |
| @Autowired(required = false) | |
| private HttpClient httpClient; | |
| @Bean | |
| public Client feignClient() { | |
| if (httpClient != null) { | |
| return new ApacheHttpClient(httpClient); | |
| } | |
| return new ApacheHttpClient(); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Configuration | |
| @ConditionalOnClass({ ILoadBalancer.class, Feign.class }) | |
| @AutoConfigureBefore(FeignAutoConfiguration.class) | |
| public class FeignRibbonClientAutoConfiguration { | |
| @Configuration | |
| @ConditionalOnClass(ApacheHttpClient.class) | |
| protected static class HttpClientConfiguration { | |
| @Autowired(required = false) | |
| private HttpClient httpClient; | |
| @Resource(name = "cachingLBClientFactory") | |
| private LBClientFactory lbClientFactory; | |
| @Bean | |
| public Client feignClient() { | |
| RibbonClient.Builder builder = RibbonClient.builder(); | |
| if (httpClient != null) { | |
| builder.delegate(new ApacheHttpClient(httpClient)); | |
| } else { | |
| builder.delegate(new ApacheHttpClient()); | |
| } | |
| if (lbClientFactory != null) { | |
| builder.lbClientFactory(lbClientFactory); | |
| } | |
| return builder.build(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment