diff options
-rw-r--r-- | tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java | 11 | ||||
-rw-r--r-- | tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java | 9 |
2 files changed, 20 insertions, 0 deletions
diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java index fa6422d80e6..5d3644e3358 100644 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java +++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/Endpoint.java @@ -7,7 +7,12 @@ import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; +import static java.net.URLEncoder.encode; import static java.nio.charset.StandardCharsets.UTF_8; /** @@ -28,6 +33,12 @@ public interface Endpoint { return send(request, HttpResponse.BodyHandlers.ofString(StandardCharsets.UTF_8)); } + /** Creates a request against the endpoint, with the given path and properties. */ + HttpRequest.Builder request(String path, Map<String, String> properties); + /** Creates a request against the endpoint, with the given path. */ + default HttpRequest.Builder request(String path) { + return request(path, Collections.emptyMap()); + } } diff --git a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java b/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java index a3f1b90f5d4..43ef179174b 100644 --- a/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java +++ b/tenant-cd/src/main/java/ai/vespa/hosted/cd/http/HttpEndpoint.java @@ -9,7 +9,10 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.time.Duration; +import java.util.Map; +import java.util.stream.Collectors; +import static java.net.URLEncoder.encode; import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.requireNonNull; @@ -50,5 +53,11 @@ public class HttpEndpoint implements Endpoint { } @Override + public HttpRequest.Builder request(String path, Map<String, String> properties) { + return HttpRequest.newBuilder(endpoint.resolve(path + + properties.entrySet().stream() + .map(entry -> encode(entry.getKey(), UTF_8) + "=" + encode(entry.getValue(), UTF_8)) + .collect(Collectors.joining("&", "?", "")))); + } } |