disable read timeout for HTTP Upload

fixes #4057
This commit is contained in:
Daniel Gultsch 2021-04-18 15:46:37 +02:00
parent ec22a39538
commit 2760f07307
2 changed files with 13 additions and 7 deletions

View File

@ -41,6 +41,8 @@ public class HttpConnectionManager extends AbstractConnectionManager {
public static final Executor EXECUTOR = Executors.newFixedThreadPool(4); public static final Executor EXECUTOR = Executors.newFixedThreadPool(4);
private static final OkHttpClient OK_HTTP_CLIENT = new OkHttpClient();
public HttpConnectionManager(XmppConnectionService service) { public HttpConnectionManager(XmppConnectionService service) {
super(service); super(service);
} }
@ -104,12 +106,15 @@ public class HttpConnectionManager extends AbstractConnectionManager {
} }
OkHttpClient buildHttpClient(final HttpUrl url, final Account account, boolean interactive) { OkHttpClient buildHttpClient(final HttpUrl url, final Account account, boolean interactive) {
return buildHttpClient(url, account, 30, interactive);
}
OkHttpClient buildHttpClient(final HttpUrl url, final Account account, int readTimeout, boolean interactive) {
final String slotHostname = url.host(); final String slotHostname = url.host();
final boolean onionSlot = slotHostname.endsWith(".onion"); final boolean onionSlot = slotHostname.endsWith(".onion");
final OkHttpClient.Builder builder = new OkHttpClient.Builder(); final OkHttpClient.Builder builder = OK_HTTP_CLIENT.newBuilder();
//builder.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.HEADERS));
builder.writeTimeout(30, TimeUnit.SECONDS); builder.writeTimeout(30, TimeUnit.SECONDS);
builder.readTimeout(30, TimeUnit.SECONDS); builder.readTimeout(readTimeout, TimeUnit.SECONDS);
setupTrustManager(builder, interactive); setupTrustManager(builder, interactive);
if (mXmppConnectionService.useTorToConnect() || account.isOnion() || onionSlot) { if (mXmppConnectionService.useTorToConnect() || account.isOnion() || onionSlot) {
builder.proxy(HttpConnectionManager.getProxy()).build(); builder.proxy(HttpConnectionManager.getProxy()).build();
@ -138,7 +143,7 @@ public class HttpConnectionManager extends AbstractConnectionManager {
} }
public static InputStream open(final HttpUrl httpUrl, final boolean tor) throws IOException { public static InputStream open(final HttpUrl httpUrl, final boolean tor) throws IOException {
final OkHttpClient.Builder builder = new OkHttpClient.Builder(); final OkHttpClient.Builder builder = OK_HTTP_CLIENT.newBuilder();
if (tor) { if (tor) {
builder.proxy(HttpConnectionManager.getProxy()).build(); builder.proxy(HttpConnectionManager.getProxy()).build();
} }

View File

@ -155,6 +155,7 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
final OkHttpClient client = mHttpConnectionManager.buildHttpClient( final OkHttpClient client = mHttpConnectionManager.buildHttpClient(
slot.put, slot.put,
message.getConversation().getAccount(), message.getConversation().getAccount(),
0,
true true
); );
final RequestBody requestBody = AbstractConnectionManager.requestBody(file, this); final RequestBody requestBody = AbstractConnectionManager.requestBody(file, this);