Skip to content

Commit 406d771

Browse files
committed
Support nonProxyHosts and proxyType settings for clients
1 parent 20f220f commit 406d771

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

client/implementation-vertx/src/main/java/io/smallrye/graphql/client/vertx/VertxClientOptionsHelper.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.vertx.core.net.JksOptions;
1010
import io.vertx.core.net.KeyCertOptions;
1111
import io.vertx.core.net.ProxyOptions;
12+
import io.vertx.core.net.ProxyType;
1213
import io.vertx.core.net.SSLOptions;
1314
import io.vertx.core.net.TrustOptions;
1415

@@ -51,6 +52,12 @@ public static void applyConfigToVertxOptions(HttpClientOptions options, GraphQLC
5152
proxyOptions.setPort(configuration.getProxyPort());
5253
proxyOptions.setUsername(configuration.getProxyUsername());
5354
proxyOptions.setPassword(configuration.getProxyPassword());
55+
proxyOptions.setType(toVertxProxyType(configuration.getProxyType()));
56+
if (configuration.getNonProxyHosts() != null) {
57+
for (String nonProxyHost : configuration.getNonProxyHosts()) {
58+
options.addNonProxyHost(nonProxyHost);
59+
}
60+
}
5461
options.setProxyOptions(proxyOptions);
5562
}
5663

@@ -59,6 +66,17 @@ public static void applyConfigToVertxOptions(HttpClientOptions options, GraphQLC
5966
}
6067
}
6168

69+
private static ProxyType toVertxProxyType(GraphQLClientConfiguration.ProxyType proxyType) {
70+
if (proxyType == null) {
71+
return ProxyType.HTTP;
72+
}
73+
return switch (proxyType) {
74+
case HTTP -> ProxyType.HTTP;
75+
case SOCKS4 -> ProxyType.SOCKS4;
76+
case SOCKS5 -> ProxyType.SOCKS5;
77+
};
78+
}
79+
6280
private static void configure(HttpClientOptions options, GraphQLClientConfiguration graphQLClientConfiguration) {
6381
options.setForceSni(graphQLClientConfiguration.usesSni() != null && graphQLClientConfiguration.usesSni());
6482
if (graphQLClientConfiguration.getHostnameVerificationAlgorithm() == null

client/implementation/src/main/java/io/smallrye/graphql/client/impl/GraphQLClientConfiguration.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,13 @@ public class GraphQLClientConfiguration {
124124
*/
125125
private String proxyPassword;
126126

127+
/**
128+
* Type of proxy to use. The default is HTTP.
129+
*/
130+
private ProxyType proxyType;
131+
132+
private List<String> nonProxyHosts;
133+
127134
/**
128135
* Maximum number of redirects to follow.
129136
*/
@@ -336,6 +343,22 @@ public Object getSslOptions() {
336343
return sslOptions;
337344
}
338345

346+
public ProxyType getProxyType() {
347+
return proxyType;
348+
}
349+
350+
public void setProxyType(ProxyType proxyType) {
351+
this.proxyType = proxyType;
352+
}
353+
354+
public List<String> getNonProxyHosts() {
355+
return nonProxyHosts;
356+
}
357+
358+
public void setNonProxyHosts(List<String> nonProxyHosts) {
359+
this.nonProxyHosts = nonProxyHosts;
360+
}
361+
339362
public void setSslOptions(Object sslOptions) {
340363
this.sslOptions = sslOptions;
341364
}
@@ -408,6 +431,9 @@ public GraphQLClientConfiguration merge(GraphQLClientConfiguration other) {
408431
if (other.proxyPassword != null) {
409432
this.proxyPassword = other.proxyPassword;
410433
}
434+
if (other.proxyType != null) {
435+
this.proxyType = other.proxyType;
436+
}
411437
if (other.maxRedirects != null) {
412438
this.maxRedirects = other.maxRedirects;
413439
}
@@ -434,4 +460,11 @@ public GraphQLClientConfiguration merge(GraphQLClientConfiguration other) {
434460
}
435461
return this;
436462
}
463+
464+
public enum ProxyType {
465+
HTTP,
466+
SOCKS4,
467+
SOCKS5
468+
}
469+
437470
}

0 commit comments

Comments
 (0)