diff --git a/.palantir/revapi.yml b/.palantir/revapi.yml new file mode 100644 index 000000000..7909ec590 --- /dev/null +++ b/.palantir/revapi.yml @@ -0,0 +1,6 @@ +acceptedBreaks: + "8.68.0": + com.palantir.conjure.java:conjure-undertow-lib: + - code: "java.method.addedToInterface" + new: "method java.util.Optional com.palantir.conjure.java.undertow.lib.RequestContext::attachment(io.undertow.util.AttachmentKey)" + justification: "Add attachment() method to RequestContext, following the pattern of cookie(). RequestContext is only implemented by conjure-java-undertow-runtime." diff --git a/conjure-java-undertow-runtime/src/main/java/com/palantir/conjure/java/undertow/runtime/ConjureContexts.java b/conjure-java-undertow-runtime/src/main/java/com/palantir/conjure/java/undertow/runtime/ConjureContexts.java index 9b2c40d95..1809331f6 100644 --- a/conjure-java-undertow-runtime/src/main/java/com/palantir/conjure/java/undertow/runtime/ConjureContexts.java +++ b/conjure-java-undertow-runtime/src/main/java/com/palantir/conjure/java/undertow/runtime/ConjureContexts.java @@ -28,6 +28,7 @@ import com.palantir.logsafe.logger.SafeLoggerFactory; import io.undertow.server.HttpServerExchange; import io.undertow.server.handlers.Cookie; +import io.undertow.util.AttachmentKey; import io.undertow.util.HeaderValues; import java.security.cert.Certificate; import java.util.Collections; @@ -81,6 +82,11 @@ public Optional firstHeader(String headerName) { return Optional.ofNullable(exchange.getRequestHeaders().getFirst(headerName)); } + @Override + public Optional attachment(AttachmentKey attachmentKey) { + return Optional.ofNullable(exchange.getAttachment(attachmentKey)); + } + @Override public Optional cookie(String cookieName) { Cookie cookie; diff --git a/conjure-undertow-lib/src/main/java/com/palantir/conjure/java/undertow/lib/RequestContext.java b/conjure-undertow-lib/src/main/java/com/palantir/conjure/java/undertow/lib/RequestContext.java index dce10b758..e1c4e5025 100644 --- a/conjure-undertow-lib/src/main/java/com/palantir/conjure/java/undertow/lib/RequestContext.java +++ b/conjure-undertow-lib/src/main/java/com/palantir/conjure/java/undertow/lib/RequestContext.java @@ -20,6 +20,7 @@ import com.google.common.collect.ListMultimap; import com.palantir.logsafe.Arg; import com.palantir.logsafe.Unsafe; +import io.undertow.util.AttachmentKey; import java.security.cert.Certificate; import java.util.List; import java.util.Optional; @@ -50,6 +51,12 @@ public interface RequestContext { */ Optional firstHeader(String headerName); + /** + * Returns the attachment associated with the given {@code key}. + * An {@link Optional#empty()} is returned if no such attachment exists. + */ + Optional attachment(AttachmentKey key); + /** * Returns the value of the cookie named {@code cookieName}. * An {@link Optional#empty()} is returned if no such cookie exists.