All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.dongliu.requests.InterceptorChain Maven / Gradle / Ivy

There is a newer version: 5.0.8
Show newest version
package net.dongliu.requests;

import java.util.List;

/**
 * @author Liu Dong
 */
class InterceptorChain implements Interceptor.InvocationTarget {
    private final List interceptorList;
    private final HttpExecutor httpExecutor;
    // use index to advance interceptor, avoid interceptor chain creation
    private int index = 0;

    public InterceptorChain(List interceptorList, HttpExecutor httpExecutor) {
        this.interceptorList = interceptorList;
        this.httpExecutor = httpExecutor;
    }

    @Override
    public RawResponse proceed(Request request) {
        if (index == interceptorList.size()) {
            return httpExecutor.proceed(request);
        }
        Interceptor interceptor = interceptorList.get(index);
        index++;
        return interceptor.intercept(this, request);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy