Skip to content

Commit

Permalink
Introduce option for multipartPostEncoderMode in REST Client builder
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Mar 28, 2024
1 parent 0827021 commit 137c028
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,14 @@ static QuarkusRestClientBuilder newBuilder() {
*/
QuarkusRestClientBuilder followRedirects(boolean follow);

/**
* Mode in which the form data are encoded. Possible values are `HTML5`, `RFC1738` and `RFC3986`.
* The modes are described in the
* <a href="https://netty.io/4.1/api/io/netty/handler/codec/http/multipart/HttpPostRequestEncoder.EncoderMode.html">Netty
* documentation</a>
*/
QuarkusRestClientBuilder multipartPostEncoderMode(String mode);

/**
* Specifies the HTTP proxy hostname/IP address and port to use for requests from client instances.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public QuarkusRestClientBuilder nonProxyHosts(String nonProxyHosts) {
return this;
}

@Override
public QuarkusRestClientBuilder multipartPostEncoderMode(String mode) {
proxy.multipartPostEncoderMode(mode);
return this;
}

@Override
public QuarkusRestClientBuilder queryParamStyle(QueryParamStyle style) {
proxy.queryParamStyle(style);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
Expand All @@ -34,6 +35,7 @@
import org.jboss.resteasy.reactive.client.impl.ClientBuilderImpl;
import org.jboss.resteasy.reactive.client.impl.ClientImpl;
import org.jboss.resteasy.reactive.client.impl.WebTargetImpl;
import org.jboss.resteasy.reactive.client.impl.multipart.PausableHttpPostRequestEncoder;
import org.jboss.resteasy.reactive.common.jaxrs.ConfigurationImpl;
import org.jboss.resteasy.reactive.common.jaxrs.MultiQueryParamMode;

Expand Down Expand Up @@ -63,6 +65,7 @@ public class RestClientBuilderImpl implements RestClientBuilder {
private boolean followRedirects;
private QueryParamStyle queryParamStyle;

private String multipartPostEncoderMode;
private String proxyHost;
private Integer proxyPort;
private String proxyUser;
Expand Down Expand Up @@ -167,6 +170,11 @@ public RestClientBuilderImpl nonProxyHosts(String nonProxyHosts) {
return this;
}

public RestClientBuilderImpl multipartPostEncoderMode(String mode) {
this.multipartPostEncoderMode = mode;
return this;
}

public RestClientBuilderImpl clientLogger(ClientLogger clientLogger) {
this.clientLogger = clientLogger;
return this;
Expand Down Expand Up @@ -435,6 +443,21 @@ public <T> T build(Class<T> aClass) throws IllegalStateException, RestClientDefi
configureProxy(globalProxy.host, globalProxy.port, restClientsConfig.proxyUser.orElse(null),
restClientsConfig.proxyPassword.orElse(null), restClientsConfig.nonProxyHosts.orElse(null));
}

if (!clientBuilder.getConfiguration().hasProperty(QuarkusRestClientProperties.MULTIPART_ENCODER_MODE)) {
PausableHttpPostRequestEncoder.EncoderMode multipartPostEncoderMode = null;
if (this.multipartPostEncoderMode != null) {
multipartPostEncoderMode = PausableHttpPostRequestEncoder.EncoderMode
.valueOf(this.multipartPostEncoderMode.toUpperCase(Locale.ROOT));
} else if (restClientsConfig.multipartPostEncoderMode.isPresent()) {
multipartPostEncoderMode = PausableHttpPostRequestEncoder.EncoderMode
.valueOf(restClientsConfig.multipartPostEncoderMode.get().toUpperCase(Locale.ROOT));
}
if (multipartPostEncoderMode != null) {
clientBuilder.property(QuarkusRestClientProperties.MULTIPART_ENCODER_MODE, multipartPostEncoderMode);
}
}

ClientImpl client = clientBuilder.build();
WebTargetImpl target = (WebTargetImpl) client.target(uri);
target.setParamConverterProviders(paramConverterProviders);
Expand Down

0 comments on commit 137c028

Please sign in to comment.