increased the default timeout when using proxy
This commit is contained in:
@@ -4,6 +4,7 @@ import com.vitorpamplona.amethyst.model.Account
|
|||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import java.net.InetSocketAddress
|
import java.net.InetSocketAddress
|
||||||
import java.net.Proxy
|
import java.net.Proxy
|
||||||
|
import java.time.Duration
|
||||||
|
|
||||||
object HttpClient {
|
object HttpClient {
|
||||||
private var proxy: Proxy? = null
|
private var proxy: Proxy? = null
|
||||||
@@ -13,7 +14,14 @@ object HttpClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getHttpClient(): OkHttpClient {
|
fun getHttpClient(): OkHttpClient {
|
||||||
return OkHttpClient.Builder().proxy(proxy).build()
|
val seconds = if (proxy != null) 20L else 10L
|
||||||
|
val duration = Duration.ofSeconds(seconds)
|
||||||
|
return OkHttpClient.Builder()
|
||||||
|
.proxy(proxy)
|
||||||
|
.readTimeout(duration)
|
||||||
|
.connectTimeout(duration)
|
||||||
|
.writeTimeout(duration)
|
||||||
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getProxy(): Proxy? {
|
fun getProxy(): Proxy? {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import okhttp3.Response
|
|||||||
import okhttp3.WebSocket
|
import okhttp3.WebSocket
|
||||||
import okhttp3.WebSocketListener
|
import okhttp3.WebSocketListener
|
||||||
import java.net.Proxy
|
import java.net.Proxy
|
||||||
|
import java.time.Duration
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
enum class FeedType {
|
enum class FeedType {
|
||||||
@@ -24,12 +25,13 @@ class Relay(
|
|||||||
var activeTypes: Set<FeedType> = FeedType.values().toSet(),
|
var activeTypes: Set<FeedType> = FeedType.values().toSet(),
|
||||||
proxy: Proxy?
|
proxy: Proxy?
|
||||||
) {
|
) {
|
||||||
init {
|
val seconds = if (proxy != null) 20L else 10L
|
||||||
println("Tor: ${proxy != null} url: $url")
|
val duration = Duration.ofSeconds(seconds)
|
||||||
}
|
|
||||||
|
|
||||||
private val httpClient = OkHttpClient.Builder()
|
private val httpClient = OkHttpClient.Builder()
|
||||||
.proxy(proxy)
|
.proxy(proxy)
|
||||||
|
.readTimeout(duration)
|
||||||
|
.connectTimeout(duration)
|
||||||
|
.writeTimeout(duration)
|
||||||
.followRedirects(true)
|
.followRedirects(true)
|
||||||
.followSslRedirects(true)
|
.followSslRedirects(true)
|
||||||
.build()
|
.build()
|
||||||
|
|||||||
Reference in New Issue
Block a user