aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server/src
diff options
context:
space:
mode:
authorJon Marius Venstad <jonmv@gmail.com>2022-04-08 11:44:56 +0200
committerJon Marius Venstad <jonmv@gmail.com>2022-04-08 11:44:56 +0200
commit55d1186ed64c35b27f7a6acae2821b81c648c377 (patch)
tree661ee03bc2fdb36a073a81ff1f45dcf39885694e /controller-server/src
parent5e317721430b7c6d849d93cfef5323795fa7a524 (diff)
Constant time append to Path as well, and add length()
Diffstat (limited to 'controller-server/src')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ProxyRequest.java6
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ServiceApiResponse.java4
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/configserver/ConfigServerApiHandler.java2
3 files changed, 6 insertions, 6 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ProxyRequest.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ProxyRequest.java
index 8b89c2300e4..79f0088a214 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ProxyRequest.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/proxy/ProxyRequest.java
@@ -33,8 +33,8 @@ public class ProxyRequest {
ProxyRequest(Method method, URI uri, Map<String, List<String>> headers, InputStream body, List<URI> targets, Path path) {
this.requestUri = HttpURL.from(uri);
- if ( requestUri.path().segments().size() < path.segments().size()
- || ! requestUri.path().tail(path.segments().size()).equals(path)) {
+ if ( requestUri.path().length() < path.length()
+ || ! requestUri.path().tail(path.length()).equals(path)) {
throw new IllegalArgumentException(Text.format("Request %s does not end with proxy %s", requestUri.path(), path));
}
if (targets.isEmpty()) {
@@ -69,7 +69,7 @@ public class ProxyRequest {
}
public URI getControllerPrefixUri() {
- Path prefixPath = requestUri.path().cut(targetPath.segments().size()).withTrailingSlash();
+ Path prefixPath = requestUri.path().cut(targetPath.length()).withTrailingSlash();
return requestUri.withPath(prefixPath).withQuery(Query.empty()).asURI();
}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ServiceApiResponse.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ServiceApiResponse.java
index 41d891a0987..67b47aa976a 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ServiceApiResponse.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ServiceApiResponse.java
@@ -173,8 +173,8 @@ class ServiceApiResponse extends HttpResponse {
private HttpURL generateLocalLinkPrefix(String identifier, Path restPath) {
Path proxiedPath = Path.parse(identifier).append(restPath);
- if (requestUri.path().tail(proxiedPath.segments().size()).equals(proxiedPath)) {
- return requestUri.withPath(requestUri.path().cut(proxiedPath.segments().size()));
+ if (requestUri.path().tail(proxiedPath.length()).equals(proxiedPath)) {
+ return requestUri.withPath(requestUri.path().cut(proxiedPath.length()));
} else {
throw new IllegalStateException("Expected the resource " + requestUri.path() + " to end with " + proxiedPath);
}
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/configserver/ConfigServerApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/configserver/ConfigServerApiHandler.java
index 99632203645..8caa741d737 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/configserver/ConfigServerApiHandler.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/configserver/ConfigServerApiHandler.java
@@ -94,7 +94,7 @@ public class ConfigServerApiHandler extends AuditLoggingRequestHandler {
throw new IllegalArgumentException("No such zone: " + zoneId.value());
}
- if (path.getRest().segments().size() < 2 || ! WHITELISTED_APIS.contains(path.getRest().head(2).withTrailingSlash())) {
+ if (path.getRest().length() < 2 || ! WHITELISTED_APIS.contains(path.getRest().head(2).withTrailingSlash())) {
return ErrorResponse.forbidden("Cannot access " + path.getRest() +
" through /configserver/v1, following APIs are permitted: " + WHITELISTED_APIS.stream()
.map(p -> "/" + String.join("/", p.segments()) + "/")