Merge pull request #692 from kortov/bugfix-691

Move init for TelegramFileDownloader to constructor, fix it for proxy usage
This commit is contained in:
Ruben Bermudez 2019-11-23 16:32:50 +00:00 committed by GitHub
commit 26f83bd4bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,9 +65,9 @@ public abstract class DefaultAbsSender extends AbsSender {
protected final ExecutorService exe;
private final ObjectMapper objectMapper = new ObjectMapper();
private final DefaultBotOptions options;
private volatile CloseableHttpClient httpClient;
private volatile RequestConfig requestConfig;
private final TelegramFileDownloader telegramFileDownloader = new TelegramFileDownloader(this::getBotToken);
private final CloseableHttpClient httpClient;
private final RequestConfig requestConfig;
private final TelegramFileDownloader telegramFileDownloader;
protected DefaultAbsSender(DefaultBotOptions options) {
super();
@ -76,11 +76,14 @@ public abstract class DefaultAbsSender extends AbsSender {
this.options = options;
httpClient = TelegramHttpClientBuilder.build(options);
this.telegramFileDownloader = new TelegramFileDownloader(httpClient, this::getBotToken);
configureHttpContext();
requestConfig = options.getRequestConfig();
if (requestConfig == null) {
requestConfig = RequestConfig.copy(RequestConfig.custom().build())
final RequestConfig configFromOptions = options.getRequestConfig();
if (configFromOptions != null) {
this.requestConfig = configFromOptions;
} else {
this.requestConfig = RequestConfig.copy(RequestConfig.custom().build())
.setSocketTimeout(SOCKET_TIMEOUT)
.setConnectTimeout(SOCKET_TIMEOUT)
.setConnectionRequestTimeout(SOCKET_TIMEOUT).build();