Skip to content

Support source address for outgoing connections - #160

Merged
3dgiordano merged 3 commits into
developmentfrom
SOURCE-ADDRESS
Aug 21, 2026
Merged

Support source address for outgoing connections#160
3dgiordano merged 3 commits into
developmentfrom
SOURCE-ADDRESS

Conversation

@3dgiordano

@3dgiordano 3dgiordano commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

This pull request adds support for binding outgoing HTTP connections to a specific local (source) address, enabling IP spoofing in HTTP sampler. This matches the behavior of the HTTPClient 4 (HC4) implementation, allowing users to specify which network interface or IP address to use for outgoing requests. The implementation ensures that all protocol-specific clients and connectors are correctly bound, and updates the client cache key to account for the source address configuration.

Key changes include:

Source Address Binding Support:

  • Added a new method setSourceAddress to HTTP2JettyClient that binds all outgoing connections and connectors (including QUIC/HTTP/3) to a specified source address, or restores the OS default if none is specified. This ensures correct IP spoofing and matches user expectations from other JMeter HTTP implementations. [1] [2]

Sampler Integration and Configuration:

  • Updated HTTP2Sampler to resolve the source address before client creation, fail the sample if the address is invalid, and ensure the client cache key separates clients by source address configuration. This prevents clients with different source addresses from being incorrectly shared. [1] [2]

Utility and Resolution Logic:

  • Introduced JMeterSourceAddressResolver, a utility class that resolves the correct source address based on sampler and global configuration, emulating the logic from HTTPClient 4 and handling interface/device lookups and error scenarios gracefully.

Testing:

  • Added comprehensive tests in HTTP2JettyClientSourceAddressTest to verify binding behavior, error handling, and correct cache key separation for different source addresses and types.

Dependency and Import Updates:

  • Updated imports and internal data structures in HTTP2JettyClient to support the new functionality, including tracking connectors and handling additional networking classes. [1] [2]

These changes collectively ensure that JMeter users can reliably control the source address for HTTP requests, with robust error handling and test coverage.

Comment on lines +959 to +965
private void appendSourceAddressKey(StringBuilder key) {
String ipSource = getIpSource();
if (ipSource == null || ipSource.trim().isEmpty()) {
return;
}
key.append(";ipsrc=").append(ipSource.trim()).append('/').append(getIpSourceType());
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could it be possible that we miss the fallback case here? If getIpSource() is empty but httpclient.localaddress is set, would those clients still share the same cache key?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch — they do share the key today. It's safe in practice because httpclient.localaddress is global: every sampler that falls back to it binds to the same address, so sharing one client is the right outcome and keying on it would fragment the cache for no benefit.

The assumption it rests on is that the property never moves. JMeter itself guarantees that — HTTPHCAbstractImpl.localAddress is a static final read once in a static initializer, so a runtime change has no effect there, and HC4 doesn't need it in HttpClientKey at all since it applies the address per request via RequestConfig.

We read it per resolution, which is more dynamic than HC4, so the assumption is ours rather than JMeter's. Closed it: the key now includes the property value when no sampler field is set, via JMeterSourceAddressResolver.cacheKeyFor() so the precedence rule lives next to resolve(). Two tests added.

@3dgiordano

Copy link
Copy Markdown
Collaborator Author

@copilot resolve the merge conflicts in this pull request

Copilot AI commented Aug 21, 2026

Copy link
Copy Markdown

@3dgiordano Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub.

You can ask me to try again later by mentioning me in a new comment.

If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: 6ffe20a8-2841-4d74-9d2d-6f86e420f8e0

Sorry for the inconvenience!

# Conflicts:
#	src/main/java/com/blazemeter/jmeter/http2/core/HTTP2JettyClient.java
#	src/main/java/com/blazemeter/jmeter/http2/sampler/HTTP2Sampler.java

Co-authored-by: 3dgiordano <797057+3dgiordano@users.noreply.github.com>

Copilot AI commented Aug 21, 2026

Copy link
Copy Markdown

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in fef1b9a. Both sets of changes are now combined: connectors (source address) and dnsResolver (DNS cache manager) fields coexist in HTTP2JettyClient, buildClient() passes both buildProfileConfig() and getDNSResolver() while also calling setSourceAddress, and buildProfileKey() calls both appendSourceAddressKey and appendDnsResolverKey.

@3dgiordano
3dgiordano merged commit 7c05f88 into development Aug 21, 2026
2 checks passed
@3dgiordano
3dgiordano deleted the SOURCE-ADDRESS branch August 21, 2026 17:34
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