原图来自:https://blog.csdn.net/luanlouis/article/details/82821294
所有注册的feign client
org.springframework.cloud.openfeign.FeignAutoConfiguration#feignContext
决定使用哪种client的地方
org.springframework.cloud.openfeign.FeignAutoConfiguration.OkHttpFeignConfiguration#feignClient
org.springframework.cloud.openfeign.FeignAutoConfiguration.HttpClientFeignConfiguration#feignClient
feign.Client.Default#Default
feign 所有拦截器
feign.SynchronousMethodHandler#targetRequest
Request targetRequest(RequestTemplate template) {
for (RequestInterceptor interceptor : requestInterceptors) {
interceptor.apply(template);
}
return target.apply(template);
}
feign feign 发送请求的地方(接口)
feign.Client#execute
默认的jdk 发送请求的地方
feign.Client.Default#execute
httpclient 发送请求的地方
org.apache.http.protocol.HttpRequestExecutor#doSendRequest
httpclient request 拦截器
org.apache.http.protocol.HttpRequestExecutor#preProcess
org.apache.http.protocol.ImmutableHttpProcessor#process(org.apache.http.HttpRequest, org.apache.http.protocol.HttpContext)
@Override
public void process(
final HttpResponse response,
final HttpContext context) throws IOException, HttpException {
for (final HttpResponseInterceptor responseInterceptor : this.responseInterceptors) {
responseInterceptor.process(response, context);
}
}
httpclient response 拦截器
org.apache.http.protocol.HttpRequestExecutor#postProcess
org.apache.http.protocol.ImmutableHttpProcessor#process(org.apache.http.HttpResponse, org.apache.http.protocol.HttpContext)
@Override
public void process(
final HttpResponse response,
final HttpContext context) throws IOException, HttpException {
for (final HttpResponseInterceptor responseInterceptor : this.responseInterceptors) {
responseInterceptor.process(response, context);
}
}
okhttp 发送请求的地方
okhttp3.internal.http.CallServerInterceptor#intercept
okhttp 拦截器
okhttp3.RealCall#getResponseWithInterceptorChain
Response getResponseWithInterceptorChain() throws IOException {
// Build a full stack of interceptors.
List<Interceptor> interceptors = new ArrayList<>();
interceptors.addAll(client.interceptors());
interceptors.add(retryAndFollowUpInterceptor);
interceptors.add(new BridgeInterceptor(client.cookieJar()));
interceptors.add(new CacheInterceptor(client.internalCache()));
interceptors.add(new ConnectInterceptor(client));
if (!forWebSocket) {
interceptors.addAll(client.networkInterceptors());
}
interceptors.add(new CallServerInterceptor(forWebSocket));
Interceptor.Chain chain = new RealInterceptorChain(
interceptors, null, null, null, 0, originalRequest);
return chain.proceed(originalRequest);
}
标签:Feign,http,springcloud,interceptors,feign,protocol,apache,组件,org
From: https://www.cnblogs.com/mysgk/p/17746979.html