mirror of
https://gitlab.com/oeffi/public-transport-enabler.git
synced 2025-07-18 16:29:51 +00:00
Support for network proxies.
This commit is contained in:
parent
1e6f55d6ba
commit
86b2d5a2f3
2 changed files with 15 additions and 1 deletions
|
@ -18,6 +18,7 @@
|
||||||
package de.schildbach.pte;
|
package de.schildbach.pte;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.Proxy;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -78,6 +79,10 @@ public abstract class AbstractNetworkProvider implements NetworkProvider {
|
||||||
httpClient.setUserAgent(userAgent);
|
httpClient.setUserAgent(userAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setProxy(final Proxy proxy) {
|
||||||
|
httpClient.setProxy(proxy);
|
||||||
|
}
|
||||||
|
|
||||||
protected void setTimeZone(final String timeZoneId) {
|
protected void setTimeZone(final String timeZoneId) {
|
||||||
this.timeZone = TimeZone.getTimeZone(timeZoneId);
|
this.timeZone = TimeZone.getTimeZone(timeZoneId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.Proxy;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
|
@ -75,6 +76,8 @@ public final class HttpClient {
|
||||||
private String sessionCookieName = null;
|
private String sessionCookieName = null;
|
||||||
@Nullable
|
@Nullable
|
||||||
private Cookie sessionCookie = null;
|
private Cookie sessionCookie = null;
|
||||||
|
@Nullable
|
||||||
|
private Proxy proxy = null;
|
||||||
private boolean trustAllCertificates = false;
|
private boolean trustAllCertificates = false;
|
||||||
@Nullable
|
@Nullable
|
||||||
private CertificatePinner certificatePinner = null;
|
private CertificatePinner certificatePinner = null;
|
||||||
|
@ -118,6 +121,10 @@ public final class HttpClient {
|
||||||
this.sessionCookieName = sessionCookieName;
|
this.sessionCookieName = sessionCookieName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setProxy(final Proxy proxy) {
|
||||||
|
this.proxy = proxy;
|
||||||
|
}
|
||||||
|
|
||||||
public void setTrustAllCertificates(final boolean trustAllCertificates) {
|
public void setTrustAllCertificates(final boolean trustAllCertificates) {
|
||||||
this.trustAllCertificates = trustAllCertificates;
|
this.trustAllCertificates = trustAllCertificates;
|
||||||
}
|
}
|
||||||
|
@ -193,8 +200,10 @@ public final class HttpClient {
|
||||||
request.header("Cookie", sessionCookie.toString());
|
request.header("Cookie", sessionCookie.toString());
|
||||||
|
|
||||||
final OkHttpClient okHttpClient;
|
final OkHttpClient okHttpClient;
|
||||||
if (trustAllCertificates || certificatePinner != null || sslAcceptAllHostnames) {
|
if (proxy != null || trustAllCertificates || certificatePinner != null || sslAcceptAllHostnames) {
|
||||||
final OkHttpClient.Builder builder = OKHTTP_CLIENT.newBuilder();
|
final OkHttpClient.Builder builder = OKHTTP_CLIENT.newBuilder();
|
||||||
|
if (proxy != null)
|
||||||
|
builder.proxy(proxy);
|
||||||
if (trustAllCertificates)
|
if (trustAllCertificates)
|
||||||
trustAllCertificates(builder);
|
trustAllCertificates(builder);
|
||||||
if (certificatePinner != null)
|
if (certificatePinner != null)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue