2

My project use spring-cloud-starter-openfeign.(version 2.1.0)
open feign is using feign-okhttp as http client and I know it uses ok-http3 internally.

I want the OkHttp3 connection to be reset or delete from connection-pool when http request gets a 500 error response.

To do that I need to detect a 500 error, so I figured I could use a network interceptor.

However, the RealConnection object I get with chain.getConnection() doesn't seem to have any methods to reset or close the connection.

How can I implement what I have in mind?

    @Bean
    public OkHttpClient client() {
        return new OkHttpClient(
            new okhttp3.OkHttpClient.Builder()
                .addNetworkInterceptor(new ResetConnection())
                .build());
    }

    public static class ResetConnection implements Interceptor {

        @Override
        public Response intercept(Chain chain) throws IOException {
            okhttp3.Request request = chain.request();
            Response response = chain.proceed(request);

            if (response.code() >= 500 && response.code() < 600) {
                    // ???????????
            }

            return response;
        }
    }

0 Answers0