Skip to content

Commit b928c82

Browse files
committed
shared http util
1 parent d05a5c1 commit b928c82

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/main/java/org/maxgamer/quickshop/util/HttpUtil.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ public class HttpUtil {
3232
protected static final com.google.common.cache.Cache<String, String> requestCachePool = CacheBuilder.newBuilder()
3333
.expireAfterWrite(7, TimeUnit.DAYS)
3434
.build();
35-
private final OkHttpClient client = new OkHttpClient.Builder()
35+
private static final OkHttpClient client = new OkHttpClient.Builder()
3636
.cache(new Cache(getCacheFolder(), 50L * 1024L * 1024L)).build();
3737

3838
public static HttpUtil create() {
3939
return new HttpUtil();
4040
}
4141

4242
public static Response makeGet(@NotNull String url) throws IOException {
43-
return HttpUtil.create().getClient().newCall(new Request.Builder().get().url(url).build()).execute();
43+
return client.newCall(new Request.Builder().get().url(url).build()).execute();
4444
}
4545

4646
public static String createGet(@NotNull String url) {
4747
String cache = requestCachePool.getIfPresent(url);
4848
if (cache != null) {
4949
return cache;
5050
}
51-
try (Response response = HttpUtil.create().getClient().newCall(new Request.Builder().get().url(url).build()).execute()) {
51+
try (Response response = client.newCall(new Request.Builder().get().url(url).build()).execute()) {
5252
val body = response.body();
5353
if (body == null) {
5454
return null;
@@ -65,10 +65,10 @@ public static String createGet(@NotNull String url) {
6565
}
6666

6767
public static Response makePost(@NotNull String url, @NotNull RequestBody body) throws IOException {
68-
return HttpUtil.create().getClient().newCall(new Request.Builder().post(body).url(url).build()).execute();
68+
return client.newCall(new Request.Builder().post(body).url(url).build()).execute();
6969
}
7070

71-
private File getCacheFolder() {
71+
private static File getCacheFolder() {
7272
File file = new File(Util.getCacheFolder(), "okhttp_tmp");
7373
file.mkdirs();
7474
return file;

0 commit comments

Comments
 (0)