Skip to content

Add RequestContext method to get source address#2922

Open
pkoenig10 wants to merge 1 commit into
developfrom
pkoenig/sourceAddress
Open

Add RequestContext method to get source address#2922
pkoenig10 wants to merge 1 commit into
developfrom
pkoenig/sourceAddress

Conversation

@pkoenig10
Copy link
Copy Markdown
Member

There are a number of existing use cases for wanting to know the source address of a request. For example, to include in audit logs.

Today we use HttpServerExchange directly for these code paths, but it would be nice to be able to use the read-only ReqeustContext instead. This information feels aligned with the purpose of RequestContext (to provide read-only information about a request) and seems reasonable to include here.

@changelog-app
Copy link
Copy Markdown

changelog-app Bot commented Jun 4, 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 get source address

Check the box to generate changelog(s)

  • Generate changelog entry

@pkoenig10 pkoenig10 force-pushed the pkoenig/sourceAddress branch from 4851c1e to 0f9c281 Compare June 4, 2026 19:29
Comment thread .palantir/revapi.yml
Comment on lines +1 to +6
acceptedBreaks:
"8.78.0":
com.palantir.conjure.java:conjure-undertow-lib:
- code: "java.method.addedToInterface"
new: "method java.net.InetSocketAddress com.palantir.conjure.java.undertow.lib.RequestContext::sourceAddress()"
justification: "Added method to interface that should not have external implementations"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@pkoenig10 Just for SA, we have ~20 internal repos that implement this interface (mostly to create fake/test contexts) https://pl.ntr/2BN

This will unfortunately prevent them from upgrading without breaks (I don't disagree with your statement that these should not exist though)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm that is unfortunate. Do you think this prevents us from merging this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about making sourceAddress() return an Optional and default it to empty instead?

Reading through the HttpServerExchange#getSourceAddress code (and things it calls), it appears this could return null (notably, if the underlying connection is a org.xnio.nio.NioPipeStreamConnection, though I don't think we'd hit that case internally).

We could also add a convenience method that returns the value or throws if absent (e.g. maybeSourceAddress() and sourceAddress() or something)

*/
void requestArg(Arg<?> arg);

InetSocketAddress sourceAddress();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you add some javadoc to this? (every other method has it, and it feels a bit weird not to have one - one thing I would potentially specify is that this is the IP address, as opposed to the hostname?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah yup, sorry, I intended to add Javadoc here.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants