feat: Add HTTP proxy support for RestTemplate

This commit is contained in:
2025-03-11 23:55:42 +03:00
parent 1f919b056d
commit f21e3ec2b2
@@ -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 {