Skip to content

Commit c599b75

Browse files
authored
Merge pull request #939 from lowcoder-org/fix_rest_system_proxy
Use system proxy settings in REST and GRAPHQL plugins
2 parents cb27aef + 121d377 commit c599b75

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

server/api-service/lowcoder-plugins/graphqlPlugin/src/main/java/org/lowcoder/plugin/graphql/GraphQLExecutor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ public Mono<QueryExecutionResult> executeQuery(Object o, GraphQLQueryExecutionCo
244244
.then(Mono.defer(() -> {
245245
URI uri = RestApiUriBuilder.buildUri(context.getUrl(), new HashMap<>(), context.getUrlParams());
246246
WebClient.Builder webClientBuilder = WebClientBuildHelper.builder()
247+
.systemProxy()
247248
.disallowedHosts(commonConfig.getDisallowedHosts())
248249
.toWebClientBuilder();
249250

server/api-service/lowcoder-plugins/restApiPlugin/src/main/java/org/lowcoder/plugin/restapi/RestApiExecutor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ public Mono<QueryExecutionResult> executeQuery(Object webClientFilter, RestApiQu
218218
return Mono.defer(() -> authByOauth2InheritFromLogin(context))
219219
.then(Mono.defer(() -> {
220220
WebClient.Builder webClientBuilder = WebClientBuildHelper.builder()
221+
.systemProxy()
221222
.disallowedHosts(commonConfig.getDisallowedHosts())
222223
.sslConfig(context.getSslConfig())
223224
.timeoutMs(context.getTimeoutMs())

server/api-service/lowcoder-sdk/src/main/java/org/lowcoder/sdk/webclient/WebClientBuildHelper.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import org.lowcoder.sdk.plugin.common.ssl.SslConfig;
1111
import org.lowcoder.sdk.plugin.common.ssl.SslHelper;
1212
import org.lowcoder.sdk.plugin.common.ssl.VerifySelfSignedCertSslConfig;
13+
import org.springframework.boot.context.properties.PropertyMapper;
1314
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
1415
import org.springframework.web.reactive.function.client.WebClient;
1516
import org.springframework.web.reactive.function.client.WebClient.Builder;
1617
import reactor.netty.http.client.HttpClient;
1718
import reactor.netty.tcp.SslProvider;
19+
import reactor.netty.transport.ProxyProvider;
1820
import reactor.netty.transport.ProxyProvider.Proxy;
1921

2022
import javax.net.ssl.SSLException;
@@ -28,6 +30,8 @@ public class WebClientBuildHelper {
2830

2931
private static final String proxyHost;
3032
private static final String proxyPortStr;
33+
private static final String proxyUsername;
34+
private static final String proxyPassword;
3135

3236
private SslConfig sslConfig;
3337
private Set<String> disallowedHosts;
@@ -39,6 +43,8 @@ public class WebClientBuildHelper {
3943
static {
4044
proxyHost = System.getProperty("http.proxyHost");
4145
proxyPortStr = System.getProperty("http.proxyPort");
46+
proxyUsername = System.getProperty("http.proxyUsername");
47+
proxyPassword = System.getProperty("http.proxyPassword");
4248
}
4349

4450
private WebClientBuildHelper() {
@@ -92,10 +98,23 @@ public Builder toWebClientBuilder() {
9298
httpClient = httpClient.secure(sslProviderWithSelfSignedCert(verifySelfSignedCertSslConfig));
9399
}
94100
}
95-
if (systemProxy && StringUtils.isNoneBlank(proxyHost, proxyPortStr)) {
96-
httpClient = httpClient.proxy(typeSpec -> typeSpec.type(Proxy.HTTP)
97-
.host(proxyHost)
98-
.port(Integer.parseInt(proxyPortStr)));
101+
if (systemProxy && StringUtils.isNotBlank(proxyHost)) {
102+
httpClient = httpClient.proxy(typeSpec -> {
103+
ProxyProvider.Builder builder = typeSpec
104+
.type(Proxy.HTTP)
105+
.host(proxyHost);
106+
PropertyMapper mapper = PropertyMapper.get();
107+
mapper.from(proxyPortStr)
108+
.whenHasText()
109+
.to(portStr -> builder.port(Integer.parseInt(portStr)));
110+
mapper.from(proxyUsername)
111+
.whenHasText()
112+
.to(builder::username);
113+
mapper.from(proxyPassword)
114+
.whenHasText()
115+
.to(password -> builder.password(s -> password));
116+
}
117+
);
99118
}
100119
if (CollectionUtils.isNotEmpty(disallowedHosts)) {
101120
httpClient = httpClient.resolver(new SafeHostResolverGroup(disallowedHosts));

0 commit comments

Comments
 (0)