|
|
@@ -3,6 +3,7 @@ package com.njuzr.eaibackend.utils;
|
|
|
import io.netty.handler.ssl.SslContextBuilder;
|
|
|
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
|
|
@@ -23,6 +24,16 @@ import java.util.function.Consumer;
|
|
|
|
|
|
@Slf4j
|
|
|
public class WebClientUtil {
|
|
|
+
|
|
|
+ @Value("${proxy.enable}")
|
|
|
+ private Boolean enableProxy;
|
|
|
+
|
|
|
+ @Value("${proxy.host}")
|
|
|
+ private String proxyHost;
|
|
|
+
|
|
|
+ @Value("${proxy.port}")
|
|
|
+ private int proxyPort;
|
|
|
+
|
|
|
private final WebClient webClient;
|
|
|
|
|
|
public WebClientUtil() {
|
|
|
@@ -42,15 +53,20 @@ public class WebClientUtil {
|
|
|
// .baseUrl(baseUrl)
|
|
|
// .build();
|
|
|
|
|
|
-// HttpClient httpClient = HttpClient.create()
|
|
|
-// .proxy(proxy -> proxy.type(ProxyProvider.Proxy.HTTP)
|
|
|
-// .host("127.0.0.1")
|
|
|
-// .port(7890));
|
|
|
-
|
|
|
- this.webClient = WebClient.builder()
|
|
|
-// .clientConnector(new ReactorClientHttpConnector(httpClient))
|
|
|
- .baseUrl(baseUrl)
|
|
|
- .build();
|
|
|
+ if (enableProxy) {
|
|
|
+ HttpClient httpClient = HttpClient.create()
|
|
|
+ .proxy(proxy -> proxy.type(ProxyProvider.Proxy.HTTP)
|
|
|
+ .host(proxyHost)
|
|
|
+ .port(proxyPort));
|
|
|
+ this.webClient = WebClient.builder()
|
|
|
+ .clientConnector(new ReactorClientHttpConnector(httpClient))
|
|
|
+ .baseUrl(baseUrl)
|
|
|
+ .build();
|
|
|
+ } else {
|
|
|
+ this.webClient = WebClient.builder()
|
|
|
+ .baseUrl(baseUrl)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// GET请求方法
|