mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-19 20:18:05 +01:00
Set request timeouts on Fixer and CoinGecko
This commit is contained in:
@@ -14,6 +14,7 @@ import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
@@ -47,12 +48,13 @@ public class CoinGeckoClient {
|
||||
|
||||
try {
|
||||
final HttpResponse<String> response = httpClient.send(HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(quoteUri)
|
||||
.header("Accept", "application/json")
|
||||
.header("x-cg-pro-api-key", apiKey)
|
||||
.build(),
|
||||
HttpResponse.BodyHandlers.ofString());
|
||||
.GET()
|
||||
.uri(quoteUri)
|
||||
.header("Accept", "application/json")
|
||||
.header("x-cg-pro-api-key", apiKey)
|
||||
.timeout(Duration.ofSeconds(15))
|
||||
.build(),
|
||||
HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
if (response.statusCode() < 200 || response.statusCode() >= 300) {
|
||||
logger.warn("CoinGecko request failed with response: {}", response);
|
||||
|
||||
@@ -12,12 +12,13 @@ import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
import org.whispersystems.textsecuregcm.util.SystemMapper;
|
||||
|
||||
public class FixerClient {
|
||||
|
||||
private final String apiKey;
|
||||
private final String apiKey;
|
||||
private final HttpClient client;
|
||||
|
||||
public FixerClient(HttpClient client, String apiKey) {
|
||||
@@ -29,11 +30,12 @@ public class FixerClient {
|
||||
try {
|
||||
URI uri = URI.create("https://data.fixer.io/api/latest?access_key=" + apiKey + "&base=" + base);
|
||||
|
||||
HttpResponse<String> response = client.send(HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(uri)
|
||||
.build(),
|
||||
HttpResponse.BodyHandlers.ofString());
|
||||
HttpResponse<String> response = client.send(HttpRequest.newBuilder()
|
||||
.GET()
|
||||
.uri(uri)
|
||||
.timeout(Duration.ofSeconds(15))
|
||||
.build(),
|
||||
HttpResponse.BodyHandlers.ofString());
|
||||
|
||||
if (response.statusCode() < 200 || response.statusCode() >= 300) {
|
||||
throw new FixerException("Bad response: " + response.statusCode() + " " + response.toString());
|
||||
|
||||
Reference in New Issue
Block a user