feat: Add HTTP proxy support for RestTemplate
This commit is contained in:
@@ -8,6 +8,9 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestClientException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import java.net.Proxy;
|
||||
import java.net.InetSocketAddress;
|
||||
import ru.cathub.telegabot.configuration.OpenRouterConfig;
|
||||
import ru.cathub.telegabot.exception.OpenRouterException;
|
||||
import ru.cathub.telegabot.model.TextRole;
|
||||
@@ -24,7 +27,13 @@ import java.util.Map;
|
||||
public class OpenRouterServiceImpl implements OpenRouterService {
|
||||
|
||||
private final OpenRouterConfig config;
|
||||
private final RestTemplate restTemplate;
|
||||
private final RestTemplate restTemplate = createProxyRestTemplate();
|
||||
|
||||
private RestTemplate createProxyRestTemplate() {
|
||||
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
||||
factory.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("192.168.0.5", 1984)));
|
||||
return new RestTemplate(factory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChatResponse(String userMessage, TextRole role) throws OpenRouterException {
|
||||
|
||||
Reference in New Issue
Block a user