opt
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package com.zhidao.roadcondition.net
|
||||
|
||||
import android.util.Log
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.utils.network.NetConfig
|
||||
import com.zhidao.roadcondition.constant.HttpConstants
|
||||
import okhttp3.Cache
|
||||
import okhttp3.Dns
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
@@ -67,11 +70,25 @@ class HttpClient private constructor(baseUrl: String) {
|
||||
}
|
||||
|
||||
private fun getOkHttpClient(): OkHttpClient {
|
||||
val builder = OkHttpClient.Builder()
|
||||
val httpLoggingInterceptor = HttpLoggingInterceptor()
|
||||
httpLoggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
|
||||
val cacheFile = File(AbsMogoApplication.getApp().applicationContext.cacheDir, "cache")
|
||||
val cache = Cache(cacheFile, 1024 * 1024 * 50)
|
||||
return OkHttpClient.Builder()
|
||||
|
||||
val httpDns = NetConfig.instance().httpDns
|
||||
if (httpDns != null) {
|
||||
builder.dns(Dns { hostname: String? ->
|
||||
val addresses = httpDns.lookup(hostname)
|
||||
// Log.d("liyz", "addresses 1 = $addresses")
|
||||
if (addresses != null && !addresses.isEmpty()) {
|
||||
return@Dns addresses
|
||||
}
|
||||
Dns.SYSTEM.lookup(hostname)
|
||||
})
|
||||
}
|
||||
|
||||
return builder
|
||||
.addInterceptor(httpLoggingInterceptor)
|
||||
.cache(cache)
|
||||
.connectTimeout(DEFAULT_CONNECT_TIME, TimeUnit.SECONDS)
|
||||
|
||||
Reference in New Issue
Block a user