Set HttpClient timeouts

Signed-off-by: Graham <gpe@openrs2.org>
bzip2
Graham 3 years ago
parent be1f293b0a
commit ab2c56f0af
  1. 2
      archive/src/main/kotlin/org/openrs2/archive/cache/nxt/MusicStreamClient.kt
  2. 2
      archive/src/main/kotlin/org/openrs2/archive/jav/JavConfig.kt
  3. 2
      archive/src/main/kotlin/org/openrs2/archive/key/JsonKeyDownloader.kt
  4. 2
      archive/src/main/kotlin/org/openrs2/archive/key/PolarKeyDownloader.kt
  5. 2
      archive/src/main/kotlin/org/openrs2/archive/key/RuneLiteKeyDownloader.kt
  6. 2
      archive/src/main/kotlin/org/openrs2/archive/name/RuneStarNameDownloader.kt
  7. 2
      http/src/main/kotlin/org/openrs2/http/HttpClientProvider.kt

@ -8,6 +8,7 @@ import org.openrs2.http.checkStatusCode
import java.net.URI import java.net.URI
import java.net.http.HttpClient import java.net.http.HttpClient
import java.net.http.HttpRequest import java.net.http.HttpRequest
import java.time.Duration
public class MusicStreamClient( public class MusicStreamClient(
private val client: HttpClient, private val client: HttpClient,
@ -19,6 +20,7 @@ public class MusicStreamClient(
val request = HttpRequest.newBuilder(uri) val request = HttpRequest.newBuilder(uri)
.GET() .GET()
.timeout(Duration.ofSeconds(30))
.build() .build()
val response = client.sendAsync(request, byteBufBodyHandler).await() val response = client.sendAsync(request, byteBufBodyHandler).await()

@ -9,6 +9,7 @@ import java.net.URI
import java.net.http.HttpClient import java.net.http.HttpClient
import java.net.http.HttpRequest import java.net.http.HttpRequest
import java.net.http.HttpResponse import java.net.http.HttpResponse
import java.time.Duration
public data class JavConfig( public data class JavConfig(
public val config: Map<String, String>, public val config: Map<String, String>,
@ -19,6 +20,7 @@ public data class JavConfig(
public suspend fun download(client: HttpClient, url: String): JavConfig { public suspend fun download(client: HttpClient, url: String): JavConfig {
val request = HttpRequest.newBuilder(URI(url)) val request = HttpRequest.newBuilder(URI(url))
.GET() .GET()
.timeout(Duration.ofSeconds(30))
.build() .build()
val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()).await() val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()).await()

@ -9,6 +9,7 @@ import java.net.URI
import java.net.http.HttpClient import java.net.http.HttpClient
import java.net.http.HttpRequest import java.net.http.HttpRequest
import java.net.http.HttpResponse import java.net.http.HttpResponse
import java.time.Duration
public abstract class JsonKeyDownloader( public abstract class JsonKeyDownloader(
private val client: HttpClient, private val client: HttpClient,
@ -17,6 +18,7 @@ public abstract class JsonKeyDownloader(
override suspend fun download(url: String): Sequence<XteaKey> { override suspend fun download(url: String): Sequence<XteaKey> {
val request = HttpRequest.newBuilder(URI(url)) val request = HttpRequest.newBuilder(URI(url))
.GET() .GET()
.timeout(Duration.ofSeconds(30))
.build() .build()
val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()).await() val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()).await()

@ -10,6 +10,7 @@ import java.net.URI
import java.net.http.HttpClient import java.net.http.HttpClient
import java.net.http.HttpRequest import java.net.http.HttpRequest
import java.net.http.HttpResponse import java.net.http.HttpResponse
import java.time.Duration
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -21,6 +22,7 @@ public class PolarKeyDownloader @Inject constructor(
override suspend fun getMissingUrls(seenUrls: Set<String>): Set<String> { override suspend fun getMissingUrls(seenUrls: Set<String>): Set<String> {
val request = HttpRequest.newBuilder(ENDPOINT) val request = HttpRequest.newBuilder(ENDPOINT)
.GET() .GET()
.timeout(Duration.ofSeconds(30))
.build() .build()
val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()).await() val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()).await()

@ -9,6 +9,7 @@ import java.net.URI
import java.net.http.HttpClient import java.net.http.HttpClient
import java.net.http.HttpRequest import java.net.http.HttpRequest
import java.net.http.HttpResponse import java.net.http.HttpResponse
import java.time.Duration
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -25,6 +26,7 @@ public class RuneLiteKeyDownloader @Inject constructor(
private suspend fun getVersion(): String { private suspend fun getVersion(): String {
val request = HttpRequest.newBuilder(VERSION_ENDPOINT) val request = HttpRequest.newBuilder(VERSION_ENDPOINT)
.GET() .GET()
.timeout(Duration.ofSeconds(30))
.build() .build()
val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()).await() val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofInputStream()).await()

@ -7,6 +7,7 @@ import java.net.URI
import java.net.http.HttpClient import java.net.http.HttpClient
import java.net.http.HttpRequest import java.net.http.HttpRequest
import java.net.http.HttpResponse import java.net.http.HttpResponse
import java.time.Duration
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
import kotlin.streams.asSequence import kotlin.streams.asSequence
@ -32,6 +33,7 @@ public class RuneStarNameDownloader @Inject constructor(
private suspend fun readTsv(uri: URI, column: Int): Sequence<String> { private suspend fun readTsv(uri: URI, column: Int): Sequence<String> {
val request = HttpRequest.newBuilder(uri) val request = HttpRequest.newBuilder(uri)
.GET() .GET()
.timeout(Duration.ofSeconds(30))
.build() .build()
val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofLines()).await() val response = client.sendAsync(request, HttpResponse.BodyHandlers.ofLines()).await()

@ -3,12 +3,14 @@ package org.openrs2.http
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor import kotlinx.coroutines.asExecutor
import java.net.http.HttpClient import java.net.http.HttpClient
import java.time.Duration
import javax.inject.Provider import javax.inject.Provider
public class HttpClientProvider : Provider<HttpClient> { public class HttpClientProvider : Provider<HttpClient> {
override fun get(): HttpClient { override fun get(): HttpClient {
return HttpClient.newBuilder() return HttpClient.newBuilder()
.authenticator(NetrcAuthenticator.read()) .authenticator(NetrcAuthenticator.read())
.connectTimeout(Duration.ofSeconds(30))
.executor(Dispatchers.IO.asExecutor()) .executor(Dispatchers.IO.asExecutor())
.followRedirects(HttpClient.Redirect.NORMAL) .followRedirects(HttpClient.Redirect.NORMAL)
.build() .build()

Loading…
Cancel
Save