package core.framework.internal.http;

import core.framework.api.http.HTTPStatus;
import okhttp3.Interceptor;
import okhttp3.Response;
import okhttp3.internal.connection.RealConnection;

import java.io.IOException;

/**
 * @author neo
 */
public class ServiceUnavailableInterceptor implements Interceptor {
    // only network interceptor is able to access connection,
    // this is to obsolete the current connection if got 503, during remote graceful shutdown process (kube/service)
    @Override
    public Response intercept(Chain chain) throws IOException {
        Response response = chain.proceed(chain.request());
        if (response.code() == HTTPStatus.SERVICE_UNAVAILABLE.code) {
            RealConnection connection = (RealConnection) chain.connection();
            connection.setNoNewExchanges(true);
        }
        return response;
    }
}

@@ -764,16 +764,58 @@
 tion();%0A
+            if (connection != null) %7B%0A    
         
@@ -854,16 +854,30 @@
 (true);%0A
+            %7D%0A
         

fix spotbugs warning