|
36 | 36 | import okhttp3.Callback; |
37 | 37 | import okhttp3.CookieJar; |
38 | 38 | import okhttp3.Headers; |
39 | | -import okhttp3.Interceptor; |
40 | 39 | import okhttp3.JavaNetCookieJar; |
41 | 40 | import okhttp3.MediaType; |
42 | 41 | import okhttp3.MultipartBody; |
@@ -174,7 +173,7 @@ public static void setCustomClientBuilder( |
174 | 173 | * https://github.com/facebook/react-native/pull/37798#pullrequestreview-1518338914 |
175 | 174 | */ |
176 | 175 | @Deprecated |
177 | | - public static interface CustomClientBuilder |
| 176 | + public interface CustomClientBuilder |
178 | 177 | extends com.facebook.react.modules.network.CustomClientBuilder {} |
179 | 178 |
|
180 | 179 | private static void applyCustomBuilder(OkHttpClient.Builder builder) { |
@@ -311,36 +310,32 @@ public void sendRequestInternal( |
311 | 310 | // response and counts bytes received. |
312 | 311 | if (useIncrementalUpdates) { |
313 | 312 | clientBuilder.addNetworkInterceptor( |
314 | | - new Interceptor() { |
315 | | - @Override |
316 | | - public Response intercept(Interceptor.Chain chain) throws IOException { |
317 | | - Response originalResponse = chain.proceed(chain.request()); |
318 | | - ProgressResponseBody responseBody = |
319 | | - new ProgressResponseBody( |
320 | | - originalResponse.body(), |
321 | | - new ProgressListener() { |
322 | | - long last = System.nanoTime(); |
323 | | - |
324 | | - @Override |
325 | | - public void onProgress( |
326 | | - long bytesWritten, long contentLength, boolean done) { |
327 | | - long now = System.nanoTime(); |
328 | | - if (!done && !shouldDispatch(now, last)) { |
329 | | - return; |
330 | | - } |
331 | | - if (responseType.equals("text")) { |
332 | | - // For 'text' responses we continuously send response data with progress |
333 | | - // info to |
334 | | - // JS below, so no need to do anything here. |
335 | | - return; |
336 | | - } |
337 | | - ResponseUtil.onDataReceivedProgress( |
338 | | - reactApplicationContext, requestId, bytesWritten, contentLength); |
339 | | - last = now; |
| 313 | + chain -> { |
| 314 | + Response originalResponse = chain.proceed(chain.request()); |
| 315 | + ProgressResponseBody responseBody = |
| 316 | + new ProgressResponseBody( |
| 317 | + originalResponse.body(), |
| 318 | + new ProgressListener() { |
| 319 | + long last = System.nanoTime(); |
| 320 | + |
| 321 | + @Override |
| 322 | + public void onProgress(long bytesWritten, long contentLength, boolean done) { |
| 323 | + long now = System.nanoTime(); |
| 324 | + if (!done && !shouldDispatch(now, last)) { |
| 325 | + return; |
340 | 326 | } |
341 | | - }); |
342 | | - return originalResponse.newBuilder().body(responseBody).build(); |
343 | | - } |
| 327 | + if (responseType.equals("text")) { |
| 328 | + // For 'text' responses we continuously send response data with progress |
| 329 | + // info to |
| 330 | + // JS below, so no need to do anything here. |
| 331 | + return; |
| 332 | + } |
| 333 | + ResponseUtil.onDataReceivedProgress( |
| 334 | + reactApplicationContext, requestId, bytesWritten, contentLength); |
| 335 | + last = now; |
| 336 | + } |
| 337 | + }); |
| 338 | + return originalResponse.newBuilder().body(responseBody).build(); |
344 | 339 | }); |
345 | 340 | } |
346 | 341 |
|
|
0 commit comments