Skip to content

Conversation

@daanjanschouten
Copy link

@daanjanschouten daanjanschouten commented Jan 13, 2026

Before this PR

Adds an attachment() method to RequestContext to read HttpServerExchange attachments. This enables retrieving current request size from Witchcraft's BytesReadHandler in application code.

RequestContext is internal-only per its javadoc, so adding methods should be safe.

After this PR

==COMMIT_MSG==
Add RequestContext method to read attachments.
==COMMIT_MSG==

@changelog-app
Copy link

changelog-app bot commented Jan 13, 2026

Generate changelog in changelog/@unreleased

Type (Select exactly one)

  • Feature (Adding new functionality)
  • Improvement (Improving existing functionality)
  • Fix (Fixing an issue with existing functionality)
  • Break (Creating a new major version by breaking public APIs)
  • Deprecation (Removing functionality in a non-breaking way)
  • Migration (Automatically moving data/functionality to a new system)

Description

Add RequestContext method to read attachments.

Check the box to generate changelog(s)

  • Generate changelog entry

@changelog-app
Copy link

changelog-app bot commented Jan 13, 2026

Successfully generated changelog entry!

Need to regenerate?

Simply interact with the changelog bot comment again to regenerate these entries.


📋Changelog Preview

✨ Features

  • Add RequestContext method to read attachments. (#2771)

@daanjanschouten daanjanschouten changed the title Expose attachment key in RequestContext Add RequestContext method to read attachments Jan 13, 2026
@daanjanschouten daanjanschouten marked this pull request as ready for review January 14, 2026 13:34
Comment on lines +54 to +58
/**
* 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);
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.

* 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);
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants