in plugins-verifier-service/src/main/kotlin/org/jetbrains/plugins/verifier/service/network/RetrofitUtil.kt [25:57]
fun createOkHttpClient(
needLog: Boolean,
timeOut: Long,
timeUnit: TimeUnit
) = OkHttpClient.Builder()
.dispatcher(
Dispatcher(
Executors.newCachedThreadPool(
ThreadFactoryBuilder()
.setNameFormat("plugin-verifier-service-http-%d")
.setDaemon(true)
.build()
)
)
)
.addInterceptor { chain: Interceptor.Chain ->
// Manually handle PUT redirect,
// can be removed when this issue will be fixed https://github.com/square/okhttp/issues/3111
val request = chain.request()
val response = chain.proceed(request)
if (response.code != 307 && response.code != 308) {
return@addInterceptor response
}
val location = response.header(LOCATION) ?: return@addInterceptor response
val locationUrl = if (location.startsWith("/")) {
//Relative URL, like /files/a.txt -> http://host.com/files/a.txt
request.url.resolve(location)!!.toUrl()
} else {
URL(location)
}
val redirectedRequest = request.newBuilder().url(locationUrl).removeHeader("Authorization").build()
chain.proceed(redirectedRequest)
}