Skip to content

Commit

Permalink
Update 2024-02-28-okhttp源码分析.md
Browse files Browse the repository at this point in the history
  • Loading branch information
nooblong committed Feb 28, 2024
1 parent ff49130 commit a92b40e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions _posts/2024-02-28-okhttp源码分析.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ protected void execute() {

通过以上同步请求和异步请求的整体分析,总体流程大概清楚了。如下图:

![请求流程](./img/whole/%E8%AF%B7%E6%B1%82%E6%B5%81%E7%A8%8B.png)
![请求流程](img/whole/%E8%AF%B7%E6%B1%82%E6%B5%81%E7%A8%8B.png)

可以得出,都是通过`dispatcher`加入各自的队列,然后最终的请求执行关键就是在`ReallCall`中的`getResponseWithInterceptorChain`方法 ,不同点异步调用会有一个线程池来调用,所以这也是通过异步调用的网络请求,为什么回调是在子线程的原因。下面看看关键`Dispatcher`类**和**`getResponseWithInterceptorChain`方法了。

Expand Down Expand Up @@ -450,7 +450,7 @@ dispatcher.setIdleCallback(new Runnable() {

通过`dispatcher`的调度后,最终都会通过`interceptor`,进行请求的拦截器处理。

![img](./img/whole/interceptorsCore.png)
![img](img/whole/interceptorsCore.png)

> 图为官网okhttp core交互图。

Expand Down Expand Up @@ -515,7 +515,7 @@ public Response proceed(Request request, StreamAllocation streamAllocation, Http

从上面代码可以看出,除去`if`判断的代码之后,关键就在注释的地方,调用的是下一个拦截器。最终得到`Response`结果。整体流程如下图:

![okhttp_interceptor](./img/whole/okhttp_interceptor.png)
![okhttp_interceptor](img/whole/okhttp_interceptor.png)

下面分来来看看这五个拦截器。

Expand Down

0 comments on commit a92b40e

Please sign in to comment.