Skip to content

Commit

Permalink
When there is no bind address, configure the default one (#3313)
Browse files Browse the repository at this point in the history
Related to #1531
  • Loading branch information
violetagg authored Jun 25, 2024
1 parent fe241fe commit 2bb16a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ protected TransportConfig(TransportConfig parent) {
this.preferNative = parent.preferNative;
}

protected void bindAddress(Supplier<? extends SocketAddress> bindAddressSupplier) {
this.bindAddress = bindAddressSupplier;
}

/**
* Return the channel type this configuration is associated with, it can be one of the following.
* <ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package reactor.netty.http.client;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URI;
import java.time.Duration;
Expand Down Expand Up @@ -1355,10 +1356,17 @@ public final HttpClient protocol(HttpProtocol... supportedProtocols) {
HttpClientConfig config = dup.configuration();
config.protocols(supportedProtocols);

if (config.checkProtocol(h3) && !isHttp3Available()) {
throw new UnsupportedOperationException(
"To enable HTTP/3 support, you must add the dependency `io.netty.incubator:netty-incubator-codec-http3`" +
" to the class path first");
if (config.checkProtocol(h3)) {
if (!isHttp3Available()) {
throw new UnsupportedOperationException(
"To enable HTTP/3 support, you must add the dependency `io.netty.incubator:netty-incubator-codec-http3`" +
" to the class path first");
}

Supplier<? extends SocketAddress> bindAddressSupplier = config.bindAddress();
if ((bindAddressSupplier == null || bindAddressSupplier.get() == null)) {
config.bindAddress(() -> new InetSocketAddress(0));
}
}

boolean isH2c = config.checkProtocol(HttpClientConfig.h2c);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,11 @@ public AddressResolverGroup<?> defaultAddressResolverGroup() {
return HttpResources.get().getOrCreateDefaultResolver();
}

@Override
protected void bindAddress(Supplier<? extends SocketAddress> bindAddressSupplier) {
super.bindAddress(bindAddressSupplier);
}

@Override
protected ConnectionObserver defaultConnectionObserver() {
if (doAfterRequest == null && doAfterResponseSuccess == null && doOnRedirect == null &&
Expand Down

0 comments on commit 2bb16a9

Please sign in to comment.