Fix issue #225 - Add proxy for uploads
This commit is contained in:
parent
357c34d9f3
commit
834ee4ab17
|
@ -1610,9 +1610,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
|
||||||
;
|
;
|
||||||
request.addParameter("filename", fileName).setMaxRetries(maxUploadRetryTimes)
|
request.addParameter("filename", fileName).setMaxRetries(maxUploadRetryTimes)
|
||||||
.startUpload();
|
.startUpload();
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException | FileNotFoundException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,7 +163,11 @@ import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
|
import java.net.Authenticator;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.PasswordAuthentication;
|
||||||
|
import java.net.Proxy;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -4610,6 +4614,8 @@ public class Helper {
|
||||||
|
|
||||||
|
|
||||||
public static OkHttpClient getHttpClient(Context context) {
|
public static OkHttpClient getHttpClient(Context context) {
|
||||||
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
|
boolean proxyEnabled = sharedpreferences.getBoolean(Helper.SET_PROXY_ENABLED, false);
|
||||||
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
|
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder()
|
||||||
.followRedirects(true)
|
.followRedirects(true)
|
||||||
.followSslRedirects(true)
|
.followSslRedirects(true)
|
||||||
|
@ -4618,6 +4624,35 @@ public class Helper {
|
||||||
.writeTimeout(30, TimeUnit.SECONDS)
|
.writeTimeout(30, TimeUnit.SECONDS)
|
||||||
.readTimeout(30, TimeUnit.SECONDS)
|
.readTimeout(30, TimeUnit.SECONDS)
|
||||||
.cache(null);
|
.cache(null);
|
||||||
|
if (proxyEnabled) {
|
||||||
|
Proxy proxy;
|
||||||
|
int type = sharedpreferences.getInt(Helper.SET_PROXY_TYPE, 0);
|
||||||
|
try {
|
||||||
|
String host = sharedpreferences.getString(Helper.SET_PROXY_HOST, "127.0.0.1");
|
||||||
|
int port = sharedpreferences.getInt(Helper.SET_PROXY_PORT, 8118);
|
||||||
|
if (type == 0)
|
||||||
|
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
|
||||||
|
else
|
||||||
|
proxy = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(host, port));
|
||||||
|
final String login = sharedpreferences.getString(Helper.SET_PROXY_LOGIN, null);
|
||||||
|
final String pwd = sharedpreferences.getString(Helper.SET_PROXY_PASSWORD, null);
|
||||||
|
if (login != null) {
|
||||||
|
Authenticator authenticator = new Authenticator() {
|
||||||
|
public PasswordAuthentication getPasswordAuthentication() {
|
||||||
|
assert pwd != null;
|
||||||
|
return (new PasswordAuthentication(login,
|
||||||
|
pwd.toCharArray()));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Authenticator.setDefault(authenticator);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
proxy = null;
|
||||||
|
}
|
||||||
|
if( proxy != null) {
|
||||||
|
clientBuilder.proxy(proxy);
|
||||||
|
}
|
||||||
|
}
|
||||||
return enableTls12OnPreLollipop(clientBuilder).build();
|
return enableTls12OnPreLollipop(clientBuilder).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue