|
|
@@ -12,17 +12,12 @@ import okhttp3.Credentials
|
|
|
import okhttp3.HttpUrl
|
|
|
import okhttp3.Interceptor
|
|
|
import okhttp3.OkHttpClient
|
|
|
-import okhttp3.internal.http.RealResponseBody
|
|
|
-import okhttp3.internal.http.promisesBody
|
|
|
-import okio.buffer
|
|
|
-import okio.source
|
|
|
import java.net.InetSocketAddress
|
|
|
import java.net.Proxy
|
|
|
import java.util.concurrent.ConcurrentHashMap
|
|
|
import java.util.concurrent.ThreadFactory
|
|
|
import java.util.concurrent.ThreadPoolExecutor
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
-import java.util.zip.GZIPInputStream
|
|
|
|
|
|
private val proxyClientCache: ConcurrentHashMap<String, OkHttpClient> by lazy {
|
|
|
ConcurrentHashMap()
|
|
|
@@ -107,38 +102,7 @@ val okHttpClient: OkHttpClient by lazy {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- builder.addInterceptor { chain ->
|
|
|
- val request = chain.request()
|
|
|
- val requestBuilder = request.newBuilder()
|
|
|
-
|
|
|
- var transparentGzip = false
|
|
|
- if (request.header("Accept-Encoding") == null && request.header("Range") == null) {
|
|
|
- transparentGzip = true
|
|
|
- requestBuilder.header("Accept-Encoding", "gzip")
|
|
|
- }
|
|
|
-
|
|
|
- val response = chain.proceed(requestBuilder.build())
|
|
|
-
|
|
|
- val responseBody = response.body
|
|
|
- if (transparentGzip && "gzip".equals(response.header("Content-Encoding"), ignoreCase = true)
|
|
|
- && response.promisesBody() && responseBody != null
|
|
|
- ) {
|
|
|
- val responseBuilder = response.newBuilder()
|
|
|
- val gzipSource = GZIPInputStream(responseBody.byteStream()).source()
|
|
|
- val strippedHeaders = response.headers.newBuilder()
|
|
|
- .removeAll("Content-Encoding")
|
|
|
- .removeAll("Content-Length")
|
|
|
- .build()
|
|
|
- responseBuilder.run {
|
|
|
- headers(strippedHeaders)
|
|
|
- val contentType = response.header("Content-Type")
|
|
|
- body(RealResponseBody(contentType, -1L, gzipSource.buffer()))
|
|
|
- build()
|
|
|
- }
|
|
|
- } else {
|
|
|
- response
|
|
|
- }
|
|
|
- }
|
|
|
+ builder.addInterceptor(DecompressInterceptor)
|
|
|
builder.build().apply {
|
|
|
val okHttpName =
|
|
|
OkHttpClient::class.java.name.removePrefix("okhttp3.").removeSuffix("Client")
|