diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-11-24 22:14:29 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-11-24 22:14:29 +0100 |
commit | cddc8a2de3a78e981420ebe60c51c689e28213ab (patch) | |
tree | 12ecca6fe958af71dc7c5a50c7e8039ef5111f91 /container-core | |
parent | 91b7755bb8e2e05e54864732c0d7ca0c2b3d200a (diff) |
Add back methods accidentally removed.
Diffstat (limited to 'container-core')
-rw-r--r-- | container-core/src/main/java/com/yahoo/jdisc/http/filter/util/FilterUtils.java | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/container-core/src/main/java/com/yahoo/jdisc/http/filter/util/FilterUtils.java b/container-core/src/main/java/com/yahoo/jdisc/http/filter/util/FilterUtils.java index dd9700e6f9a..fafb8f38fb0 100644 --- a/container-core/src/main/java/com/yahoo/jdisc/http/filter/util/FilterUtils.java +++ b/container-core/src/main/java/com/yahoo/jdisc/http/filter/util/FilterUtils.java @@ -1,6 +1,8 @@ // Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.jdisc.http.filter.util; +import com.yahoo.jdisc.http.filter.DiscFilterRequest; +import com.yahoo.jdisc.http.server.jetty.RequestUtils; import com.yahoo.json.Jackson; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.node.ObjectNode; @@ -11,8 +13,11 @@ import com.yahoo.jdisc.handler.ResponseHandler; import com.yahoo.jdisc.http.Cookie; import java.io.UncheckedIOException; +import java.net.URI; +import java.net.URISyntaxException; import java.nio.ByteBuffer; import java.util.List; +import java.util.Optional; /** * Helper methods for auth0/okta request filters. @@ -21,12 +26,33 @@ import java.util.List; */ public class FilterUtils { + public static boolean isDifferentOrigin(DiscFilterRequest request) { + try { + String origin = request.getHeader("Origin"); + if (origin != null && !URI.create(origin).getHost().equals(request.getServerName())) + return true; + } catch (RuntimeException ignored) { } + return false; + } + public static void sendRedirectResponse(ResponseHandler handler, List<Cookie> cookies, String location) { Response response = createResponse(Response.Status.FOUND, cookies); response.headers().add("Location", location); handler.handleResponse(response).close(null); } + public static URI createUriFromRequest(DiscFilterRequest request, String path, Optional<String> hostOverride) { + try { + // Prefer local port as observed by client over local listen port + int port = Optional.ofNullable((Integer)request.getAttribute(RequestUtils.JDICS_REQUEST_PORT)) + .orElse(request.getUri().getPort()); + String host = hostOverride.orElse(request.getServerName()); + return new URI(request.getScheme(), null, host, port, path, null, null); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } + } + public static void sendMessageResponse(ResponseHandler handler, List<Cookie> cookies, int code, String message) { Response response = createResponse(code, cookies); ContentChannel contentChannel = handler.handleResponse(response); |