mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-04-24 00:00:03 +08:00
WIP: fix disableRedirect()
This commit is contained in:
@@ -31,9 +31,10 @@ abstract class CordovaHttpBase implements Runnable {
|
||||
protected JSONObject params;
|
||||
protected JSONObject headers;
|
||||
protected int timeout;
|
||||
protected boolean followRedirects;
|
||||
protected CallbackContext callbackContext;
|
||||
|
||||
public CordovaHttpBase(String method, String url, String serializer, Object data, JSONObject headers, int timeout,
|
||||
public CordovaHttpBase(String method, String url, String serializer, Object data, JSONObject headers, int timeout, boolean followRedirects,
|
||||
CallbackContext callbackContext) {
|
||||
|
||||
this.method = method;
|
||||
@@ -42,10 +43,11 @@ abstract class CordovaHttpBase implements Runnable {
|
||||
this.data = data;
|
||||
this.headers = headers;
|
||||
this.timeout = timeout;
|
||||
this.followRedirects = followRedirects;
|
||||
this.callbackContext = callbackContext;
|
||||
}
|
||||
|
||||
public CordovaHttpBase(String method, String url, JSONObject params, JSONObject headers, int timeout,
|
||||
public CordovaHttpBase(String method, String url, JSONObject params, JSONObject headers, int timeout, boolean followRedirects,
|
||||
CallbackContext callbackContext) {
|
||||
|
||||
this.method = method;
|
||||
@@ -53,6 +55,7 @@ abstract class CordovaHttpBase implements Runnable {
|
||||
this.params = params;
|
||||
this.headers = headers;
|
||||
this.timeout = timeout;
|
||||
this.followRedirects = followRedirects;
|
||||
this.callbackContext = callbackContext;
|
||||
}
|
||||
|
||||
@@ -108,7 +111,7 @@ abstract class CordovaHttpBase implements Runnable {
|
||||
}
|
||||
|
||||
protected void prepareRequest(HttpRequest request) throws JSONException {
|
||||
request.followRedirects(true /* @TODO */);
|
||||
request.followRedirects(this.followRedirects);
|
||||
request.readTimeout(this.timeout);
|
||||
request.acceptCharset("UTF-8");
|
||||
request.uncompress(true);
|
||||
|
||||
@@ -13,9 +13,9 @@ class CordovaHttpDownload extends CordovaHttpBase {
|
||||
private String filePath;
|
||||
|
||||
public CordovaHttpDownload(String url, JSONObject params, JSONObject headers, String filePath, int timeout,
|
||||
CallbackContext callbackContext) {
|
||||
boolean followRedirects, CallbackContext callbackContext) {
|
||||
|
||||
super("GET", url, params, headers, timeout, callbackContext);
|
||||
super("GET", url, params, headers, timeout, followRedirects, callbackContext);
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@ import org.json.JSONObject;
|
||||
|
||||
class CordovaHttpOperation extends CordovaHttpBase {
|
||||
public CordovaHttpOperation(String method, String url, String serializer, Object data, JSONObject headers,
|
||||
int timeout, CallbackContext callbackContext) {
|
||||
int timeout, boolean followRedirects, CallbackContext callbackContext) {
|
||||
|
||||
super(method, url, serializer, data, headers, timeout, callbackContext);
|
||||
super(method, url, serializer, data, headers, timeout, followRedirects, callbackContext);
|
||||
}
|
||||
|
||||
public CordovaHttpOperation(String method, String url, JSONObject params, JSONObject headers, int timeout,
|
||||
CallbackContext callbackContext) {
|
||||
boolean followRedirects, CallbackContext callbackContext) {
|
||||
|
||||
super(method, url, params, headers, timeout, callbackContext);
|
||||
super(method, url, params, headers, timeout, followRedirects, callbackContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class CordovaHttpPlugin extends CordovaPlugin {
|
||||
int timeout = args.getInt(3) * 1000;
|
||||
|
||||
CordovaHttpOperation request = new CordovaHttpOperation(method.toUpperCase(), url, params, headers, timeout,
|
||||
callbackContext);
|
||||
followRedirects, callbackContext);
|
||||
|
||||
cordova.getThreadPool().execute(request);
|
||||
|
||||
@@ -100,8 +100,8 @@ public class CordovaHttpPlugin extends CordovaPlugin {
|
||||
JSONObject headers = args.getJSONObject(3);
|
||||
int timeout = args.getInt(4) * 1000;
|
||||
|
||||
CordovaHttpOperation request = new CordovaHttpOperation(method.toUpperCase(), url, serializer, data, headers, timeout,
|
||||
callbackContext);
|
||||
CordovaHttpOperation request = new CordovaHttpOperation(method.toUpperCase(), url, serializer, data, headers,
|
||||
timeout, followRedirects, callbackContext);
|
||||
|
||||
cordova.getThreadPool().execute(request);
|
||||
|
||||
@@ -116,8 +116,8 @@ public class CordovaHttpPlugin extends CordovaPlugin {
|
||||
String uploadName = args.getString(4);
|
||||
int timeout = args.getInt(5) * 1000;
|
||||
|
||||
CordovaHttpUpload upload = new CordovaHttpUpload(url, params, headers,
|
||||
filePath, uploadName, timeout, callbackContext);
|
||||
CordovaHttpUpload upload = new CordovaHttpUpload(url, params, headers, filePath, uploadName, timeout,
|
||||
followRedirects, callbackContext);
|
||||
|
||||
cordova.getThreadPool().execute(upload);
|
||||
|
||||
@@ -131,7 +131,8 @@ public class CordovaHttpPlugin extends CordovaPlugin {
|
||||
String filePath = args.getString(3);
|
||||
int timeout = args.getInt(4) * 1000;
|
||||
|
||||
CordovaHttpDownload download = new CordovaHttpDownload(url, params, headers, filePath, timeout, callbackContext);
|
||||
CordovaHttpDownload download = new CordovaHttpDownload(url, params, headers, filePath, timeout, followRedirects,
|
||||
callbackContext);
|
||||
|
||||
cordova.getThreadPool().execute(download);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.json.JSONObject;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
public class CordovaHttpResponse {
|
||||
class CordovaHttpResponse {
|
||||
private int status;
|
||||
private String url;
|
||||
private Map<String, List<String>> headers;
|
||||
|
||||
@@ -10,15 +10,14 @@ import java.net.URI;
|
||||
import org.apache.cordova.CallbackContext;
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
||||
class CordovaHttpUpload extends CordovaHttpBase {
|
||||
private String filePath;
|
||||
private String uploadName;
|
||||
|
||||
public CordovaHttpUpload(String url, JSONObject params, JSONObject headers, String filePath, String uploadName,
|
||||
int timeout, CallbackContext callbackContext) {
|
||||
int timeout, boolean followRedirects, CallbackContext callbackContext) {
|
||||
|
||||
super("POST", url, params, headers, timeout, callbackContext);
|
||||
super("POST", url, params, headers, timeout, followRedirects, callbackContext);
|
||||
this.filePath = filePath;
|
||||
this.uploadName = uploadName;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user