added optional request timeout to http repositories

This commit is contained in:
MineTec committed 2026-10-14 21:07:27 +02:00
1 parent ddcbdbaec5
commit 882bacf57b
2 files changed
+23

No files matched your search

@@ -10,6 +10,7 @@ import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;
@@ -74,6 +75,19 @@ public abstract class HttpRepository extends Repository {
return this.execute(request, outputType, null);
}
/**
* Like {@link #get(String, Class)}, but the request fails with an exception once the timeout has passed.
*/
protected <TOutput> ReqResp<TOutput> get(String command, Duration timeout, Class<TOutput> outputType) {
HttpRequest request = this.getRequestBuilder(this.getUri(command, parameters -> {
}))
.timeout(timeout)
.GET()
.build();
return this.execute(request, outputType, null);
}
private URI getUri(String command, Consumer<URIBuilder> parameters) {
try {
URIBuilder builder = new URIBuilder(this.basePath + "/" + command);