Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .palantir/revapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
acceptedBreaks:
"8.68.0":
com.palantir.conjure.java:conjure-undertow-lib:
- code: "java.method.addedToInterface"
new: "method <T> java.util.Optional<T> com.palantir.conjure.java.undertow.lib.RequestContext::attachment(io.undertow.util.AttachmentKey<T>)"
justification: "Add attachment() method to RequestContext, following the pattern of cookie(). RequestContext is only implemented by conjure-java-undertow-runtime."
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -81,6 +82,11 @@ public Optional<String> firstHeader(String headerName) {
return Optional.ofNullable(exchange.getRequestHeaders().getFirst(headerName));
}

@Override
public <T> Optional<T> attachment(AttachmentKey<T> attachmentKey) {
return Optional.ofNullable(exchange.getAttachment(attachmentKey));
}

@Override
public Optional<String> cookie(String cookieName) {
Cookie cookie;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,6 +51,12 @@ public interface RequestContext {
*/
Optional<String> firstHeader(String headerName);

/**
* Returns the attachment associated with the given {@code key}.
* An {@link Optional#empty()} is returned if no such attachment exists.
*/
<T> Optional<T> attachment(AttachmentKey<T> key);
Comment on lines +54 to +58
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is appropriate for RequestContext.

RequestContext is designed to be a read-only interface for getting requests data not supported by the tool used to generate the endpoint implementations (either conjure or conjure-undertow-annotations). From the Javadoc for this interface:

Interface providing a view over data provided by the the original HTTP request including request headers and query parameters.

This method is meaningfully different. It's not exposing information about the request - it's exposing information from the underlying HttpServerExchange for this request.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables retrieving current request size from Witchcraft's BytesReadHandler in application code.

I'm also not convinced that we want to make this part of the public API of Witchcraft. This increases the surface area of the Witchcraft API and removes a degree of freedom for evolving our implementation in the future if necessary.


/**
* Returns the value of the cookie named {@code cookieName}.
* An {@link Optional#empty()} is returned if no such cookie exists.
Expand Down