mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-07-26 00:00:14 +08:00
changed booleans to AtomicBooleans
This commit is contained in:
@@ -13,6 +13,7 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.BufferedReader;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
@@ -32,8 +33,8 @@ public abstract class CordovaHttp {
|
||||
protected static final String TAG = "CordovaHTTP";
|
||||
protected static final String CHARSET = "UTF-8";
|
||||
|
||||
private static boolean sslPinning;
|
||||
private static boolean acceptAllCerts;
|
||||
private static AtomicBoolean sslPinning = new AtomicBoolean(false);
|
||||
private static AtomicBoolean acceptAllCerts = new AtomicBoolean(false);
|
||||
|
||||
private String urlString;
|
||||
private Map<?, ?> params;
|
||||
@@ -44,22 +45,20 @@ public abstract class CordovaHttp {
|
||||
this.urlString = urlString;
|
||||
this.params = params;
|
||||
this.headers = headers;
|
||||
this.sslPinning = sslPinning;
|
||||
this.acceptAllCerts = acceptAllCerts;
|
||||
this.callbackContext = callbackContext;
|
||||
}
|
||||
|
||||
public static void enableSSLPinning(boolean enable) {
|
||||
sslPinning = enable;
|
||||
if (sslPinning) {
|
||||
acceptAllCerts = false;
|
||||
sslPinning.set(enable);
|
||||
if (enable) {
|
||||
acceptAllCerts.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void acceptAllCerts(boolean accept) {
|
||||
acceptAllCerts = accept;
|
||||
if (acceptAllCerts) {
|
||||
sslPinning = false;
|
||||
acceptAllCerts.set(accept);
|
||||
if (accept) {
|
||||
sslPinning.set(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,36 +66,24 @@ public abstract class CordovaHttp {
|
||||
return this.urlString;
|
||||
}
|
||||
|
||||
protected void setUrlString(String urlString) {
|
||||
this.urlString = urlString;
|
||||
}
|
||||
|
||||
protected Map<?, ?> getParams() {
|
||||
return this.params;
|
||||
}
|
||||
|
||||
protected void setParams(Map<?, ?> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
protected Map<String, String> getHeaders() {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
protected void setHeaders(Map<String, String> headers) {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
protected CallbackContext getCallbackContext() {
|
||||
return this.callbackContext;
|
||||
}
|
||||
|
||||
protected HttpRequest setupSecurity(HttpRequest request) {
|
||||
if (acceptAllCerts) {
|
||||
if (acceptAllCerts.get()) {
|
||||
request.trustAllCerts();
|
||||
request.trustAllHosts();
|
||||
}
|
||||
if (sslPinning) {
|
||||
if (sslPinning.get()) {
|
||||
request.pinToCerts();
|
||||
}
|
||||
return request;
|
||||
|
||||
Reference in New Issue
Block a user