diff options
author | Bjørn Christian Seime <bjorncs@vespa.ai> | 2023-11-17 17:05:53 +0100 |
---|---|---|
committer | Bjørn Christian Seime <bjorncs@vespa.ai> | 2023-11-17 17:05:53 +0100 |
commit | 781ceb006b6c053bbe4eb3d76ff0e01b46f05ccb (patch) | |
tree | 1cc11377d703d96848b6ccafbf22fd19ce68efac /application/src/main/java | |
parent | 2b9917fe639f2bd27fecf3fd4a7d6b0ca0d3382b (diff) |
Allow configuration of remote address in 'application' request
Diffstat (limited to 'application/src/main/java')
-rw-r--r-- | application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java | 1 | ||||
-rw-r--r-- | application/src/main/java/com/yahoo/application/container/handler/Request.java | 18 |
2 files changed, 19 insertions, 0 deletions
diff --git a/application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java b/application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java index c54b3f60cf9..1b4862c75c0 100644 --- a/application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java +++ b/application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java @@ -90,6 +90,7 @@ final class SynchronousRequestResponseHandler { URI.create(request.getUri()), com.yahoo.jdisc.http.HttpRequest.Method.valueOf(request.getMethod().name())); request.getUserPrincipal().ifPresent(httpRequest::setUserPrincipal); + request.remoteAddress().ifPresent(httpRequest::setRemoteAddress); discRequest = httpRequest; } else { discRequest = new com.yahoo.jdisc.Request(currentContainer, URI.create(request.getUri())); diff --git a/application/src/main/java/com/yahoo/application/container/handler/Request.java b/application/src/main/java/com/yahoo/application/container/handler/Request.java index b6dff44269b..d877258cb15 100644 --- a/application/src/main/java/com/yahoo/application/container/handler/Request.java +++ b/application/src/main/java/com/yahoo/application/container/handler/Request.java @@ -3,6 +3,7 @@ package com.yahoo.application.container.handler; import com.yahoo.api.annotations.Beta; +import java.net.SocketAddress; import java.nio.charset.StandardCharsets; import java.security.Principal; import java.util.Map; @@ -24,6 +25,7 @@ public class Request { private final Method method; private final Map<String, Object> attributes = new ConcurrentHashMap<>(); private final Principal userPrincipal; + private final SocketAddress remoteAddress; /** * Creates a Request with an empty body. @@ -73,10 +75,24 @@ public class Request { * @param principal the user principal of the request */ public Request(String uri, byte[] body, Method method, Principal principal) { + this(uri, body, method, principal, null); + } + + /** + * Creates a Request with a message body, method and user principal. + * + * @param uri the URI of the request + * @param body the body of the request + * @param method the method of the request + * @param principal the user principal of the request + * @param remoteAddress the remote address of the request + */ + public Request(String uri, byte[] body, Method method, Principal principal, SocketAddress remoteAddress) { this.uri = uri; this.body = body; this.method = method; this.userPrincipal = principal; + this.remoteAddress = remoteAddress; } /** @@ -122,6 +138,8 @@ public class Request { return attributes; } + public Optional<SocketAddress> remoteAddress() { return Optional.ofNullable(remoteAddress); } + @Override public String toString() { String bodyStr = (body == null || body.length == 0) ? "[empty]" : "[omitted]"; |