diff --git a/plugin.xml b/plugin.xml
index aedd4f1..2102a7b 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -28,8 +28,8 @@
-
-
+
+
@@ -80,7 +80,7 @@
-
+
diff --git a/src/android/com/synconset/CordovaHTTP/CordovaHTTP.java b/src/android/com/synconset/CordovaHTTP/CordovaHttpPlugin.java
similarity index 99%
rename from src/android/com/synconset/CordovaHTTP/CordovaHTTP.java
rename to src/android/com/synconset/CordovaHTTP/CordovaHttpPlugin.java
index e50bcb5..9949dc6 100644
--- a/src/android/com/synconset/CordovaHTTP/CordovaHTTP.java
+++ b/src/android/com/synconset/CordovaHTTP/CordovaHttpPlugin.java
@@ -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;
diff --git a/src/android/com/synconset/CordovaHTTP/HTTP.java b/src/android/com/synconset/CordovaHTTP/HTTP.java
index abefd70..cafa300 100644
--- a/src/android/com/synconset/CordovaHTTP/HTTP.java
+++ b/src/android/com/synconset/CordovaHTTP/HTTP.java
@@ -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();
diff --git a/src/android/com/synconset/CordovaHTTP/HTTPGet.java b/src/android/com/synconset/CordovaHTTP/HTTPGet.java
index a7ac1a9..0bf83b5 100644
--- a/src/android/com/synconset/CordovaHTTP/HTTPGet.java
+++ b/src/android/com/synconset/CordovaHTTP/HTTPGet.java
@@ -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);
diff --git a/src/android/com/synconset/CordovaHTTP/HTTPPost.java b/src/android/com/synconset/CordovaHTTP/HTTPPost.java
index 8cc4bed..45dfa5f 100644
--- a/src/android/com/synconset/CordovaHTTP/HTTPPost.java
+++ b/src/android/com/synconset/CordovaHTTP/HTTPPost.java
@@ -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);
diff --git a/src/ios/CordovaHTTP.m b/src/ios/CordovaHTTP.m
index b6630c1..f751aa2 100644
--- a/src/ios/CordovaHTTP.m
+++ b/src/ios/CordovaHTTP.m
@@ -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];
diff --git a/src/ios/CordovaHTTP.h b/src/ios/CordovaHttpPlugin.h
similarity index 95%
rename from src/ios/CordovaHTTP.h
rename to src/ios/CordovaHttpPlugin.h
index e955c82..41c1415 100644
--- a/src/ios/CordovaHTTP.h
+++ b/src/ios/CordovaHttpPlugin.h
@@ -3,7 +3,7 @@
#import
#import
-@interface CordovaHTTP : CDVPlugin
+@interface CordovaHttpPlugin : CDVPlugin
- (void)setAuthorizationHeaderWithUsernameAndPassword:(CDVInvokedUrlCommand*)command;
- (void)setHeader:(CDVInvokedUrlCommand*)command;
diff --git a/src/ios/HTTPManager.h b/src/ios/HTTPManager.h
index 987633c..e4633d2 100644
--- a/src/ios/HTTPManager.h
+++ b/src/ios/HTTPManager.h
@@ -21,7 +21,7 @@
#import
#import "AFHTTPRequestOperationManager.h"
-@interface HTTPManager : AFHTTPRequestOperationManager
+@interface HttpManager : AFHTTPRequestOperationManager
+ (instancetype)sharedClient;
diff --git a/src/ios/HTTPManager.m b/src/ios/HTTPManager.m
index fcad9a2..ee1f17b 100644
--- a/src/ios/HTTPManager.m
+++ b/src/ios/HTTPManager.m
@@ -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;