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