From dc048bece6a861db2b5ecb68835ddbe75d681299 Mon Sep 17 00:00:00 2001 From: chentianming Date: Mon, 4 Jul 2022 11:09:01 +0800 Subject: [PATCH] doc update --- README.md | 41 +++++++++++-------- README_EN.md | 39 +++++++++++------- .../CustomSourceOkHttpClientRegistrar.java | 14 +++---- 3 files changed, 55 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 530d561..a6908e5 100644 --- a/README.md +++ b/README.md @@ -209,25 +209,32 @@ retrofit: @Slf4j @Component public class CustomSourceOkHttpClientRegistrar implements SourceOkHttpClientRegistrar { - @Override - public void register(SourceOkHttpClientRegistry registry) { - - // 替换默认的SourceOkHttpClient - registry.register(Constants.DEFAULT_SOURCE_OK_HTTP_CLIENT, new OkHttpClient.Builder() - .addInterceptor(chain -> { - log.info("============替换默认的SourceOkHttpClient============="); + + @Override + public void register(SourceOkHttpClientRegistry registry) { + + // 替换默认的SourceOkHttpClient,可以用来修改全局OkhttpClient设置 + registry.register(Constants.DEFAULT_SOURCE_OK_HTTP_CLIENT, new OkHttpClient.Builder() + .connectTimeout(Duration.ofSeconds(5)) + .writeTimeout(Duration.ofSeconds(5)) + .readTimeout(Duration.ofSeconds(5)) + .addInterceptor(chain -> { + log.info("============replace default SourceOkHttpClient============="); return chain.proceed(chain.request()); - }) - .build()); - - // 添加新的SourceOkHttpClient - registry.register("testSourceOkHttpClient", new OkHttpClient.Builder() - .addInterceptor(chain -> { - log.info("============使用testSourceOkHttpClient============="); + }) + .build()); + + // 添加testSourceOkHttpClient + registry.register("testSourceOkHttpClient", new OkHttpClient.Builder() + .connectTimeout(Duration.ofSeconds(3)) + .writeTimeout(Duration.ofSeconds(3)) + .readTimeout(Duration.ofSeconds(3)) + .addInterceptor(chain -> { + log.info("============use testSourceOkHttpClient============="); return chain.proceed(chain.request()); - }) - .build()); - } + }) + .build()); + } } ``` diff --git a/README_EN.md b/README_EN.md index fb69cb6..21275f7 100644 --- a/README_EN.md +++ b/README_EN.md @@ -178,23 +178,32 @@ retrofit: @Slf4j @Component public class CustomSourceOkHttpClientRegistrar implements SourceOkHttpClientRegistrar { - @Override - public void register(SourceOkHttpClientRegistry registry) { - - registry.register(Constants.DEFAULT_SOURCE_OK_HTTP_CLIENT, new OkHttpClient.Builder() - .addInterceptor(chain -> { - log.info("============Replace the default SourceOkHttpClient============="); + + @Override + public void register(SourceOkHttpClientRegistry registry) { + + // replace default SourceOkHttpClient. Can be used to modify global `Okhttp Client` settings + registry.register(Constants.DEFAULT_SOURCE_OK_HTTP_CLIENT, new OkHttpClient.Builder() + .connectTimeout(Duration.ofSeconds(5)) + .writeTimeout(Duration.ofSeconds(5)) + .readTimeout(Duration.ofSeconds(5)) + .addInterceptor(chain -> { + log.info("============replace default SourceOkHttpClient============="); return chain.proceed(chain.request()); - }) - .build()); - - registry.register("testSourceOkHttpClient", new OkHttpClient.Builder() - .addInterceptor(chain -> { - log.info("============testSourceOkHttpClient============="); + }) + .build()); + + // add testSourceOkHttpClient + registry.register("testSourceOkHttpClient", new OkHttpClient.Builder() + .connectTimeout(Duration.ofSeconds(3)) + .writeTimeout(Duration.ofSeconds(3)) + .readTimeout(Duration.ofSeconds(3)) + .addInterceptor(chain -> { + log.info("============use testSourceOkHttpClient============="); return chain.proceed(chain.request()); - }) - .build()); - } + }) + .build()); + } } ``` diff --git a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/custom/okhttp/CustomSourceOkHttpClientRegistrar.java b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/custom/okhttp/CustomSourceOkHttpClientRegistrar.java index bea86e6..a7f6d5c 100644 --- a/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/custom/okhttp/CustomSourceOkHttpClientRegistrar.java +++ b/src/test/java/com/github/lianjiatech/retrofit/spring/boot/test/custom/okhttp/CustomSourceOkHttpClientRegistrar.java @@ -22,24 +22,24 @@ public class CustomSourceOkHttpClientRegistrar implements SourceOkHttpClientRegi @Override public void register(SourceOkHttpClientRegistry registry) { - // 替换默认的SourceOkHttpClient + // 替换默认的SourceOkHttpClient,可以用来修改全局OkhttpClient设置 registry.register(Constants.DEFAULT_SOURCE_OK_HTTP_CLIENT, new OkHttpClient.Builder() .connectTimeout(Duration.ofSeconds(5)) .writeTimeout(Duration.ofSeconds(5)) .readTimeout(Duration.ofSeconds(5)) .addInterceptor(chain -> { - log.info("============替换默认的SourceOkHttpClient============="); + log.info("============replace default SourceOkHttpClient============="); return chain.proceed(chain.request()); }) .build()); - // 添加新的SourceOkHttpClient + // 添加testSourceOkHttpClient registry.register("testSourceOkHttpClient", new OkHttpClient.Builder() - .connectTimeout(Duration.ofSeconds(5)) - .writeTimeout(Duration.ofSeconds(5)) - .readTimeout(Duration.ofSeconds(5)) + .connectTimeout(Duration.ofSeconds(3)) + .writeTimeout(Duration.ofSeconds(3)) + .readTimeout(Duration.ofSeconds(3)) .addInterceptor(chain -> { - log.info("============使用testSourceOkHttpClient============="); + log.info("============use testSourceOkHttpClient============="); return chain.proceed(chain.request()); }) .build());