mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2024-10-06 17:22:12 +08:00
Started refactoring things so they make more sense name wise
This commit is contained in:
parent
d4fce7751d
commit
78dcc361ca
@ -28,8 +28,8 @@
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<header-file src="src/ios/CordovaHTTP.h" />
|
||||
<source-file src="src/ios/CordovaHTTP.m" />
|
||||
<header-file src="src/ios/CordovaHttpPlugin.h" />
|
||||
<source-file src="src/ios/CordovaHttpPlugin.m" />
|
||||
|
||||
<header-file src="src/ios/HTTPManager.h" />
|
||||
<source-file src="src/ios/HTTPManager.m" />
|
||||
@ -80,7 +80,7 @@
|
||||
<source-file src="src/Android/com/synconset/CordovaHTTP/HTTP.java" target-dir="src/com/synconset" />
|
||||
<source-file src="src/Android/com/synconset/CordovaHTTP/HTTPGet.java" target-dir="src/com/synconset" />
|
||||
<source-file src="src/Android/com/synconset/CordovaHTTP/HTTPPost.java" target-dir="src/com/synconset" />
|
||||
<source-file src="src/Android/com/synconset/CordovaHTTP/CordovaHTTP.java" target-dir="src/com/synconset" />
|
||||
<source-file src="src/Android/com/synconset/CordovaHTTP/CordovaHttpPlugin.java" target-dir="src/com/synconset" />
|
||||
<source-file src="src/Android/com/synconset/CordovaHTTP/VeryTrustingTrustManager.java" target-dir="src/com/synconset" />
|
||||
<source-file src="src/Android/com/synconset/CordovaHTTP/VeryTrustingHostnameVerifier.java" target-dir="src/com/synconset" />
|
||||
</platform>
|
||||
|
@ -34,7 +34,7 @@ import android.content.res.AssetManager;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
public class CordovaHTTP extends CordovaPlugin {
|
||||
public class CordovaHttpPlugin extends CordovaPlugin {
|
||||
private static final String TAG = "CordovaHTTP";
|
||||
|
||||
private SSLContext sslContext;
|
@ -13,8 +13,11 @@ import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.BufferedReader;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
|
||||
@ -67,18 +70,22 @@ public class HTTP {
|
||||
this.headers = headers;
|
||||
}
|
||||
|
||||
protected SSLContext getSSLContext() {
|
||||
return this.sslContext;
|
||||
}
|
||||
|
||||
protected HostnameVerifier getHostnameVerifier() {
|
||||
return this.hostnameVerifier;
|
||||
}
|
||||
|
||||
protected CallbackContext getCallbackContext() {
|
||||
return this.callbackContext;
|
||||
}
|
||||
|
||||
protected HttpsURLConnection openConnection(String urlString) throws MalformedURLException, IOException {
|
||||
URL url = new URL(urlString);
|
||||
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
|
||||
if (this.hostnameVerifier != null) {
|
||||
conn.setHostnameVerifier(this.hostnameVerifier);
|
||||
}
|
||||
if (this.sslContext != null) {
|
||||
conn.setSSLSocketFactory(this.sslContext.getSocketFactory());
|
||||
}
|
||||
return conn;
|
||||
}
|
||||
|
||||
protected void addHeaders(URLConnection conn) throws JSONException {
|
||||
Iterator<?> i = this.headers.keys();
|
||||
|
||||
|
@ -35,8 +35,7 @@ public class HTTPGet extends HTTP implements Runnable {
|
||||
if (params.length() > 0) {
|
||||
urlString = urlString + "?" + this.getQueryString();
|
||||
}
|
||||
URL url = new URL(urlString);
|
||||
conn = (HttpsURLConnection)url.openConnection();
|
||||
conn = this.openConnection(urlString);
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setDoInput(true);
|
||||
conn.setRequestProperty("Accept-Charset", charset);
|
||||
|
@ -34,16 +34,7 @@ public class HTTPPost extends HTTP implements Runnable {
|
||||
InputStream is = null;
|
||||
HttpsURLConnection conn = null;
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
conn = (HttpsURLConnection)url.openConnection();
|
||||
HostnameVerifier hostnameVerifier = this.getHostnameVerifier();
|
||||
if (hostnameVerifier != null) {
|
||||
conn.setHostnameVerifier(hostnameVerifier);
|
||||
}
|
||||
SSLContext context = this.getSSLContext();
|
||||
if (context != null) {
|
||||
conn.setSSLSocketFactory(this.getSSLContext().getSocketFactory());
|
||||
}
|
||||
conn = this.openConnection(urlString);
|
||||
conn.setRequestMethod("POST");
|
||||
conn.setDoInput(true);
|
||||
conn.setDoOutput(true);
|
||||
|
@ -1,15 +1,15 @@
|
||||
#import "CordovaHTTP.h"
|
||||
#import "CordovaHttpPlugin.h"
|
||||
#import "CDVFile.h"
|
||||
#import "TextResponseSerializer.h"
|
||||
#import "HTTPManager.h"
|
||||
#import "HttpManager.h"
|
||||
|
||||
@implementation CordovaHTTP
|
||||
@implementation CordovaHttpPlugin
|
||||
|
||||
- (void)setAuthorizationHeaderWithUsernameAndPassword:(CDVInvokedUrlCommand*)command {
|
||||
NSString *username = [command.arguments objectAtIndex:0];
|
||||
NSString *password = [command.arguments objectAtIndex:1];
|
||||
|
||||
[[HTTPManager sharedClient].requestSerializer setAuthorizationHeaderFieldWithUsername:username password:password];
|
||||
[[HttpManager sharedClient].requestSerializer setAuthorizationHeaderFieldWithUsername:username password:password];
|
||||
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
@ -19,14 +19,14 @@
|
||||
NSString *header = [command.arguments objectAtIndex:0];
|
||||
NSString *value = [command.arguments objectAtIndex:1];
|
||||
|
||||
[[HTTPManager sharedClient].requestSerializer setValue:value forHTTPHeaderField: header];
|
||||
[[HttpManager sharedClient].requestSerializer setValue:value forHTTPHeaderField: header];
|
||||
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
- (void)enableSSLPinning:(CDVInvokedUrlCommand*)command {
|
||||
[HTTPManager sharedClient].securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
|
||||
[HttpManager sharedClient].securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
|
||||
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
@ -36,7 +36,7 @@
|
||||
CDVPluginResult* pluginResult = nil;
|
||||
bool validate = [[command.arguments objectAtIndex:0] boolValue];
|
||||
|
||||
[HTTPManager sharedClient].securityPolicy.validatesCertificateChain = validate;
|
||||
[HttpManager sharedClient].securityPolicy.validatesCertificateChain = validate;
|
||||
|
||||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
@ -46,35 +46,35 @@
|
||||
CDVPluginResult* pluginResult = nil;
|
||||
bool allow = [[command.arguments objectAtIndex:0] boolValue];
|
||||
|
||||
[HTTPManager sharedClient].securityPolicy.allowInvalidCertificates = allow;
|
||||
[HttpManager sharedClient].securityPolicy.allowInvalidCertificates = allow;
|
||||
|
||||
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
- (void)acceptText:(CDVInvokedUrlCommand*)command {
|
||||
[HTTPManager sharedClient].responseSerializer = [TextResponseSerializer serializer];
|
||||
[HttpManager sharedClient].responseSerializer = [TextResponseSerializer serializer];
|
||||
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
- (void)acceptData:(CDVInvokedUrlCommand*)command {
|
||||
[HTTPManager sharedClient].responseSerializer = [AFHTTPResponseSerializer serializer];
|
||||
[HttpManager sharedClient].responseSerializer = [AFHTTPResponseSerializer serializer];
|
||||
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
- (void)setAcceptableContentTypes:(CDVInvokedUrlCommand*)command {
|
||||
[HTTPManager sharedClient].responseSerializer.acceptableContentTypes = [NSSet setWithArray: command.arguments];
|
||||
[HttpManager sharedClient].responseSerializer.acceptableContentTypes = [NSSet setWithArray: command.arguments];
|
||||
|
||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}
|
||||
|
||||
- (void)post:(CDVInvokedUrlCommand*)command {
|
||||
HTTPManager *manager = [HTTPManager sharedClient];
|
||||
HttpManager *manager = [HttpManager sharedClient];
|
||||
NSString *url = [command.arguments objectAtIndex:0];
|
||||
NSDictionary *parameters = [command.arguments objectAtIndex:1];
|
||||
|
||||
@ -96,7 +96,7 @@
|
||||
}
|
||||
|
||||
- (void)get:(CDVInvokedUrlCommand*)command {
|
||||
HTTPManager *manager = [HTTPManager sharedClient];
|
||||
HttpManager *manager = [HttpManager sharedClient];
|
||||
NSString *url = [command.arguments objectAtIndex:0];
|
||||
NSDictionary *parameters = [command.arguments objectAtIndex:1];
|
||||
|
||||
@ -118,7 +118,7 @@
|
||||
}
|
||||
|
||||
- (void)uploadFile:(CDVInvokedUrlCommand*)command {
|
||||
HTTPManager *manager = [HTTPManager sharedClient];
|
||||
HttpManager *manager = [HttpManager sharedClient];
|
||||
NSString *url = [command.arguments objectAtIndex:0];
|
||||
NSDictionary *parameters = [command.arguments objectAtIndex:1];
|
||||
NSString *filePath = [command.arguments objectAtIndex: 2];
|
||||
@ -154,7 +154,7 @@
|
||||
|
||||
|
||||
- (void)downloadFile:(CDVInvokedUrlCommand*)command {
|
||||
HTTPManager *manager = [HTTPManager sharedClient];
|
||||
HttpManager *manager = [HttpManager sharedClient];
|
||||
NSString *url = [command.arguments objectAtIndex:0];
|
||||
NSDictionary *parameters = [command.arguments objectAtIndex:1];
|
||||
NSString *filePath = [command.arguments objectAtIndex: 2];
|
||||
|
@ -3,7 +3,7 @@
|
||||
#import <Cordova/CDVPlugin.h>
|
||||
#import <Cordova/CDVJSON.h>
|
||||
|
||||
@interface CordovaHTTP : CDVPlugin
|
||||
@interface CordovaHttpPlugin : CDVPlugin
|
||||
|
||||
- (void)setAuthorizationHeaderWithUsernameAndPassword:(CDVInvokedUrlCommand*)command;
|
||||
- (void)setHeader:(CDVInvokedUrlCommand*)command;
|
@ -21,7 +21,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "AFHTTPRequestOperationManager.h"
|
||||
|
||||
@interface HTTPManager : AFHTTPRequestOperationManager
|
||||
@interface HttpManager : AFHTTPRequestOperationManager
|
||||
|
||||
+ (instancetype)sharedClient;
|
||||
|
||||
|
@ -18,9 +18,9 @@
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
// Modified by Andrew Stephan
|
||||
#import "HTTPManager.h"
|
||||
#import "HttpManager.h"
|
||||
|
||||
@implementation HTTPManager
|
||||
@implementation HttpManager
|
||||
|
||||
+ (instancetype)sharedClient {
|
||||
static HTTPManager *_sharedClient = nil;
|
||||
|
Loading…
Reference in New Issue
Block a user