Support source address for outgoing connections - #160
Conversation
| private void appendSourceAddressKey(StringBuilder key) { | ||
| String ipSource = getIpSource(); | ||
| if (ipSource == null || ipSource.trim().isEmpty()) { | ||
| return; | ||
| } | ||
| key.append(";ipsrc=").append(ipSource.trim()).append('/').append(getIpSourceType()); | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
|
@copilot resolve the merge conflicts in this pull request |
|
@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: 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>
Merge conflicts resolved in fef1b9a. Both sets of changes are now combined: |
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:
setSourceAddresstoHTTP2JettyClientthat 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:
HTTP2Samplerto 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:
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:
HTTP2JettyClientSourceAddressTestto verify binding behavior, error handling, and correct cache key separation for different source addresses and types.Dependency and Import Updates:
HTTP2JettyClientto 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.