co.easimart.http.EasimartNetworkInterceptor Maven / Gradle / Ivy
package co.easimart.http;
import java.io.IOException;
/**
* {@code EasimartNetworkInterceptor} is used to observe requests going out and the corresponding
* responses coming back in.
*/
public interface EasimartNetworkInterceptor {
/**
* Intercepts a {@link EasimartHttpRequest} with the help of
* {@link EasimartNetworkInterceptor.Chain} and returns the intercepted
* {@link EasimartHttpResponse}.
*
* @param chain
* The helper chain we use to get the request, proceed the request and receive the
* response.
* @return The intercepted response.
* @throws IOException
*/
EasimartHttpResponse intercept(Chain chain) throws IOException;
/**
* {@code Chain} is used to chain the interceptors. It can get the request from the previous
* interceptor, proceed the request to the next interceptor and get the response from the next
* interceptor. In most of the cases, you don't need to implement this interface.
*/
interface Chain {
/**
* Gets the {@link EasimartHttpRequest} from this chain.
*
* @return The {@link EasimartHttpRequest} of this chain.
*/
EasimartHttpRequest getRequest();
/**
* Proceeds the intercepted {@link EasimartHttpRequest} in this chain to next
* {@code EasimartNetworkInterceptor} or network and gets the {@link EasimartHttpResponse}.
*
* @param request
* The intercepted {@link EasimartHttpRequest}.
* @return The {@link EasimartHttpResponse} from next {@code EasimartNetworkInterceptor} or network.
* @throws IOException
*/
EasimartHttpResponse proceed(EasimartHttpRequest request) throws IOException;
}
}