From 050ed894d65b2d4d06a148707bfa6464b45c4847 Mon Sep 17 00:00:00 2001 From: Sefa Ilkimen Date: Mon, 14 Nov 2016 00:18:16 +0100 Subject: [PATCH 1/5] defined www interface for http methods PUT and DELETE --- www/cordovaHTTP.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/www/cordovaHTTP.js b/www/cordovaHTTP.js index a5ebe2b..2d5d7b0 100644 --- a/www/cordovaHTTP.js +++ b/www/cordovaHTTP.js @@ -87,11 +87,11 @@ var http = { validateDomainName: function (validate, success, failure) { return exec(success, failure, 'CordovaHttpPlugin', 'validateDomainName', [validate]); }, - post: function (url, params, headers, success, failure) { - params = params || {}; + post: function (url, data, headers, success, failure) { + data = data || {}; headers = headers || {}; headers = mergeHeaders(this.headers, headers); - return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, params, this.paramSerializer, headers]); + return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, data, this.paramSerializer, headers]); }, get: function (url, params, headers, success, failure) { params = params || {}; @@ -99,6 +99,18 @@ var http = { headers = mergeHeaders(this.headers, headers); return exec(success, failure, 'CordovaHttpPlugin', 'get', [url, params, headers]); }, + put: function (url, data, headers, success, failure) { + data = data || {}; + headers = headers || {}; + headers = mergeHeaders(this.headers, headers); + return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, data, this.paramSerializer, headers]); + }, + delete: function (url, params, headers, success, failure) { + params = params || {}; + headers = headers || {}; + headers = mergeHeaders(this.headers, headers); + return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, params, this.paramSerializer, headers]); + }, head: function (url, params, headers, success, failure) { headers = mergeHeaders(this.headers, headers); return exec(success, failure, 'CordovaHttpPlugin', 'head', [url, params, headers]); @@ -178,12 +190,18 @@ if (typeof angular !== 'undefined') { validateDomainName: function (validate) { return makePromise(http.validateDomainName, [validate]); }, - post: function (url, params, headers) { - return makePromise(http.post, [url, params, headers], true); + post: function (url, data, headers) { + return makePromise(http.post, [url, data, headers], true); }, get: function (url, params, headers) { return makePromise(http.get, [url, params, headers], true); }, + put: function (url, data, headers) { + return makePromise(http.put, [url, data, headers], true); + }, + delete: function (url, params, headers) { + return makePromise(http.delete, [url, params, headers], true); + }, head: function (url, params, headers) { return makePromise(http.head, [url, params, headers], true); }, From 0989de20ab8ac0f67424835462d2ebfe4659b09e Mon Sep 17 00:00:00 2001 From: Sefa Ilkimen Date: Mon, 14 Nov 2016 00:47:24 +0100 Subject: [PATCH 2/5] renamed param serializer to data serializer --- README.md | 12 ++++++------ www/cordovaHTTP.js | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a06f62a..adde98f 100644 --- a/README.md +++ b/README.md @@ -53,14 +53,14 @@ Set a header for all future requests. Takes a header and a value. cordovaHTTP.setHeader("Header", "Value"); -### setParamSerializer -Set the parameter serializer which will be used for all future POST and PUT requests. Takes a string representing the name of the serializer. +### setDataSerializer +Set the data serializer which will be used for all future POST and PUT requests. Takes a string representing the name of the serializer. - cordovaHTTP.setParamSerializer("urlencoded"); + cordovaHTTP.setDataSerializer("urlencoded"); You can choose one of these two: -* `urlencoded`: send parameters as url encoded content in body (content type "application/x-www-form-urlencoded") -* `json`: send parameters as JSON encoded content in body (content type "application/json") +* `urlencoded`: send data as url encoded content in body (content type "application/x-www-form-urlencoded") +* `json`: send data as JSON encoded content in body (content type "application/json") ## Async Functions These functions all take success and error callbacks as their last 2 arguments. @@ -97,7 +97,7 @@ Whether or not to validate the domain name in the certificate. This defaults to }); ### post -Execute a POST request. Takes a URL, parameters, and headers. +Execute a POST request. Takes a URL, data, and headers. #### success The success function receives a response object with 3 properties: status, data, and headers. Status is the HTTP response code. Data is the response from the server as a string. Headers is an object with the headers. Here's a quick example: diff --git a/www/cordovaHTTP.js b/www/cordovaHTTP.js index 2d5d7b0..5fa69a7 100644 --- a/www/cordovaHTTP.js +++ b/www/cordovaHTTP.js @@ -64,7 +64,7 @@ function checkSerializer(serializer) { var http = { headers: {}, - paramSerializer: 'urlencoded', + dataSerializer: 'urlencoded', sslPinning: false, getBasicAuthHeader: function (username, password) { return {'Authorization': 'Basic ' + b64EncodeUnicode(username + ':' + password)}; @@ -75,8 +75,8 @@ var http = { setHeader: function (header, value) { this.headers[header] = value; }, - setParamSerializer: function (serializer) { - this.paramSerializer = checkSerializer(serializer); + setDataSerializer: function (serializer) { + this.dataSerializer = checkSerializer(serializer); }, enableSSLPinning: function (enable, success, failure) { return exec(success, failure, 'CordovaHttpPlugin', 'enableSSLPinning', [enable]); @@ -91,7 +91,7 @@ var http = { data = data || {}; headers = headers || {}; headers = mergeHeaders(this.headers, headers); - return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, data, this.paramSerializer, headers]); + return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, data, this.dataSerializer, headers]); }, get: function (url, params, headers, success, failure) { params = params || {}; @@ -103,13 +103,13 @@ var http = { data = data || {}; headers = headers || {}; headers = mergeHeaders(this.headers, headers); - return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, data, this.paramSerializer, headers]); + return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, data, this.dataSerializer, headers]); }, delete: function (url, params, headers, success, failure) { params = params || {}; headers = headers || {}; headers = mergeHeaders(this.headers, headers); - return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, params, this.paramSerializer, headers]); + return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, params, this.dataSerializer, headers]); }, head: function (url, params, headers, success, failure) { headers = mergeHeaders(this.headers, headers); @@ -178,7 +178,7 @@ if (typeof angular !== 'undefined') { setHeader: function (header, value) { return http.setHeader(header, value); }, - setParamSerializer: function (serializer) { + setDataSerializer: function (serializer) { return http.setParamSerializer(serializer); }, enableSSLPinning: function (enable) { From d5b2cdaf605f527c844a0a5b3c120bc4fdcf3efb Mon Sep 17 00:00:00 2001 From: Sefa Ilkimen Date: Mon, 14 Nov 2016 13:56:54 +0100 Subject: [PATCH 3/5] implemented PUT and DELETE methods for Android and iOS --- plugin.xml | 16 +++-- .../CordovaHTTP/CordovaHttpDelete.java | 58 +++++++++++++++++ .../synconset/CordovaHTTP/CordovaHttpPut.java | 64 +++++++++++++++++++ .../cordovahttp/CordovaHttpPlugin.java | 45 ++++++++----- src/ios/CordovaHttpPlugin.h | 4 +- src/ios/CordovaHttpPlugin.m | 56 ++++++++++++++++ www/cordovaHTTP.js | 4 +- 7 files changed, 222 insertions(+), 25 deletions(-) create mode 100644 src/android/com/synconset/CordovaHTTP/CordovaHttpDelete.java create mode 100644 src/android/com/synconset/CordovaHTTP/CordovaHttpPut.java diff --git a/plugin.xml b/plugin.xml index 609f08d..381bcf0 100644 --- a/plugin.xml +++ b/plugin.xml @@ -70,14 +70,16 @@ - - - - - - - + + + + + + + + + diff --git a/src/android/com/synconset/CordovaHTTP/CordovaHttpDelete.java b/src/android/com/synconset/CordovaHTTP/CordovaHttpDelete.java new file mode 100644 index 0000000..604e6a5 --- /dev/null +++ b/src/android/com/synconset/CordovaHTTP/CordovaHttpDelete.java @@ -0,0 +1,58 @@ +/** + * A HTTP plugin for Cordova / Phonegap + */ +package com.synconset.cordovahttp; + +import java.net.UnknownHostException; + +import javax.net.ssl.SSLHandshakeException; + +import org.apache.cordova.CallbackContext; + +import org.json.JSONException; +import org.json.JSONObject; + +import com.github.kevinsawicki.http.HttpRequest; +import com.github.kevinsawicki.http.HttpRequest.HttpRequestException; + +class CordovaHttpDelete extends CordovaHttp implements Runnable { + public CordovaHttpDelete(String urlString, JSONObject data, JSONObject headers, CallbackContext callbackContext) { + super(urlString, data, headers, callbackContext); + } + + @Override + public void run() { + try { + HttpRequest request = HttpRequest.delete(this.getUrlString(), this.getParamsMap(), false); + + this.setupSecurity(request); + request.acceptCharset(CHARSET); + request.headers(this.getHeadersMap()); + + int code = request.code(); + String body = request.body(CHARSET); + JSONObject response = new JSONObject(); + + this.addResponseHeaders(request, response); + response.put("status", code); + + if (code >= 200 && code < 300) { + response.put("data", body); + this.getCallbackContext().success(response); + } else { + response.put("error", body); + this.getCallbackContext().error(response); + } + } catch (JSONException e) { + this.respondWithError("There was an error generating the response"); + } catch (HttpRequestException e) { + if (e.getCause() instanceof UnknownHostException) { + this.respondWithError(0, "The host could not be resolved"); + } else if (e.getCause() instanceof SSLHandshakeException) { + this.respondWithError("SSL handshake failed"); + } else { + this.respondWithError("There was an error with the request"); + } + } + } +} diff --git a/src/android/com/synconset/CordovaHTTP/CordovaHttpPut.java b/src/android/com/synconset/CordovaHTTP/CordovaHttpPut.java new file mode 100644 index 0000000..ac533d2 --- /dev/null +++ b/src/android/com/synconset/CordovaHTTP/CordovaHttpPut.java @@ -0,0 +1,64 @@ +/** + * A HTTP plugin for Cordova / Phonegap + */ +package com.synconset.cordovahttp; + +import java.net.UnknownHostException; + +import org.apache.cordova.CallbackContext; +import org.json.JSONException; +import org.json.JSONObject; + +import javax.net.ssl.SSLHandshakeException; + +import com.github.kevinsawicki.http.HttpRequest; +import com.github.kevinsawicki.http.HttpRequest.HttpRequestException; + +class CordovaHttpPut extends CordovaHttp implements Runnable { + public CordovaHttpPut(String urlString, JSONObject data, String serializerName, JSONObject headers, CallbackContext callbackContext) { + super(urlString, data, serializerName, headers, callbackContext); + } + + @Override + public void run() { + try { + HttpRequest request = HttpRequest.put(this.getUrlString()); + + this.setupSecurity(request); + request.acceptCharset(CHARSET); + request.headers(this.getHeadersMap()); + + if (new String("json").equals(this.getSerializerName())) { + request.contentType(request.CONTENT_TYPE_JSON, request.CHARSET_UTF8); + request.send(this.getParamsObject().toString()); + } else { + request.form(this.getParamsMap()); + } + + int code = request.code(); + String body = request.body(CHARSET); + JSONObject response = new JSONObject(); + + this.addResponseHeaders(request, response); + response.put("status", code); + + if (code >= 200 && code < 300) { + response.put("data", body); + this.getCallbackContext().success(response); + } else { + response.put("error", body); + this.getCallbackContext().error(response); + } + } catch (JSONException e) { + this.respondWithError("There was an error generating the response"); + } catch (HttpRequestException e) { + if (e.getCause() instanceof UnknownHostException) { + this.respondWithError(0, "The host could not be resolved"); + } else if (e.getCause() instanceof SSLHandshakeException) { + this.respondWithError("SSL handshake failed"); + } else { + this.respondWithError("There was an error with the request"); + } + } + } +} diff --git a/src/android/com/synconset/cordovahttp/CordovaHttpPlugin.java b/src/android/com/synconset/cordovahttp/CordovaHttpPlugin.java index c39693e..8e2c99a 100644 --- a/src/android/com/synconset/cordovahttp/CordovaHttpPlugin.java +++ b/src/android/com/synconset/cordovahttp/CordovaHttpPlugin.java @@ -34,21 +34,7 @@ public class CordovaHttpPlugin extends CordovaPlugin { @Override public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException { - if (action.equals("get")) { - String urlString = args.getString(0); - JSONObject params = args.getJSONObject(1); - JSONObject headers = args.getJSONObject(2); - CordovaHttpGet get = new CordovaHttpGet(urlString, params, headers, callbackContext); - - cordova.getThreadPool().execute(get); - } else if (action.equals("head")) { - String urlString = args.getString(0); - JSONObject params = args.getJSONObject(1); - JSONObject headers = args.getJSONObject(2); - CordovaHttpHead head = new CordovaHttpHead(urlString, params, headers, callbackContext); - - cordova.getThreadPool().execute(head); - } else if (action.equals("post")) { + if (action.equals("post")) { String urlString = args.getString(0); JSONObject params = args.getJSONObject(1); String serializerName = args.getString(2); @@ -56,6 +42,35 @@ public class CordovaHttpPlugin extends CordovaPlugin { CordovaHttpPost post = new CordovaHttpPost(urlString, params, serializerName, headers, callbackContext); cordova.getThreadPool().execute(post); + } else if (action.equals("get")) { + String urlString = args.getString(0); + JSONObject params = args.getJSONObject(1); + JSONObject headers = args.getJSONObject(2); + CordovaHttpGet get = new CordovaHttpGet(urlString, params, headers, callbackContext); + + cordova.getThreadPool().execute(get); + } else if (action.equals("put")) { + String urlString = args.getString(0); + JSONObject params = args.getJSONObject(1); + String serializerName = args.getString(2); + JSONObject headers = args.getJSONObject(3); + CordovaHttpPut put = new CordovaHttpPut(urlString, params, serializerName, headers, callbackContext); + + cordova.getThreadPool().execute(put); + } else if (action.equals("delete")) { + String urlString = args.getString(0); + JSONObject params = args.getJSONObject(1); + JSONObject headers = args.getJSONObject(2); + CordovaHttpDelete delete = new CordovaHttpDelete(urlString, params, headers, callbackContext); + + cordova.getThreadPool().execute(delete); + } else if (action.equals("head")) { + String urlString = args.getString(0); + JSONObject params = args.getJSONObject(1); + JSONObject headers = args.getJSONObject(2); + CordovaHttpHead head = new CordovaHttpHead(urlString, params, headers, callbackContext); + + cordova.getThreadPool().execute(head); } else if (action.equals("enableSSLPinning")) { try { boolean enable = args.getBoolean(0); diff --git a/src/ios/CordovaHttpPlugin.h b/src/ios/CordovaHttpPlugin.h index 917349a..24cc395 100644 --- a/src/ios/CordovaHttpPlugin.h +++ b/src/ios/CordovaHttpPlugin.h @@ -9,7 +9,9 @@ - (void)validateDomainName:(CDVInvokedUrlCommand*)command; - (void)post:(CDVInvokedUrlCommand*)command; - (void)get:(CDVInvokedUrlCommand*)command; +- (void)put:(CDVInvokedUrlCommand*)command; +- (void)delete:(CDVInvokedUrlCommand*)command; - (void)uploadFile:(CDVInvokedUrlCommand*)command; - (void)downloadFile:(CDVInvokedUrlCommand*)command; -@end \ No newline at end of file +@end diff --git a/src/ios/CordovaHttpPlugin.m b/src/ios/CordovaHttpPlugin.m index 3214524..460afd0 100644 --- a/src/ios/CordovaHttpPlugin.m +++ b/src/ios/CordovaHttpPlugin.m @@ -129,6 +129,62 @@ }]; } +- (void)put:(CDVInvokedUrlCommand*)command { + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; + manager.securityPolicy = securityPolicy; + NSString *url = [command.arguments objectAtIndex:0]; + NSDictionary *parameters = [command.arguments objectAtIndex:1]; + NSString *serializerName = [command.arguments objectAtIndex:2]; + NSDictionary *headers = [command.arguments objectAtIndex:3]; + [self setRequestSerializer: serializerName forManager: manager]; + [self setRequestHeaders: headers forManager: manager]; + + CordovaHttpPlugin* __weak weakSelf = self; + manager.responseSerializer = [TextResponseSerializer serializer]; + [manager PUT:url parameters:parameters success:^(NSURLSessionTask *task, id responseObject) { + NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; + [self setResults: dictionary withTask: task]; + [dictionary setObject:responseObject forKey:@"data"]; + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; + [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + } failure:^(NSURLSessionTask *task, NSError *error) { + NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; + [self setResults: dictionary withTask: task]; + NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding]; + [dictionary setObject:errResponse forKey:@"error"]; + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; + [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; +} + +- (void)delete:(CDVInvokedUrlCommand*)command { + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; + manager.securityPolicy = securityPolicy; + NSString *url = [command.arguments objectAtIndex:0]; + NSDictionary *parameters = [command.arguments objectAtIndex:1]; + NSDictionary *headers = [command.arguments objectAtIndex:2]; + [self setRequestSerializer: @"default" forManager: manager]; + [self setRequestHeaders: headers forManager: manager]; + + CordovaHttpPlugin* __weak weakSelf = self; + + manager.responseSerializer = [TextResponseSerializer serializer]; + [manager DELETE:url parameters:parameters success:^(NSURLSessionTask *task, id responseObject) { + NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; + [self setResults: dictionary withTask: task]; + [dictionary setObject:responseObject forKey:@"data"]; + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; + [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + } failure:^(NSURLSessionTask *task, NSError *error) { + NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; + [self setResults: dictionary withTask: task]; + NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding]; + [dictionary setObject:errResponse forKey:@"error"]; + CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; + [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + }]; +} + - (void)head:(CDVInvokedUrlCommand*)command { AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; manager.securityPolicy = securityPolicy; diff --git a/www/cordovaHTTP.js b/www/cordovaHTTP.js index 5fa69a7..2800962 100644 --- a/www/cordovaHTTP.js +++ b/www/cordovaHTTP.js @@ -103,13 +103,13 @@ var http = { data = data || {}; headers = headers || {}; headers = mergeHeaders(this.headers, headers); - return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, data, this.dataSerializer, headers]); + return exec(success, failure, 'CordovaHttpPlugin', 'put', [url, data, this.dataSerializer, headers]); }, delete: function (url, params, headers, success, failure) { params = params || {}; headers = headers || {}; headers = mergeHeaders(this.headers, headers); - return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, params, this.dataSerializer, headers]); + return exec(success, failure, 'CordovaHttpPlugin', 'delete', [url, params, headers]); }, head: function (url, params, headers, success, failure) { headers = mergeHeaders(this.headers, headers); From a0edca1b1dc9052903181ef50df918926aea5bb1 Mon Sep 17 00:00:00 2001 From: Sefa Ilkimen Date: Mon, 14 Nov 2016 14:43:24 +0100 Subject: [PATCH 4/5] updated README --- README.md | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index adde98f..68a67a3 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Cordova / Phonegap plugin for communicating with HTTP servers. Supports iOS and ## Advantages over Javascript requests - Background threading - all requests are done in a background thread. + - Handling of HTTP code 401 - read more at [Issue CB-2415](https://issues.apache.org/jira/browse/CB-2415). - SSL Pinning - read more at [LumberBlog](http://blog.lumberlabs.com/2012/04/why-app-developers-should-care-about.html). ## Updates @@ -23,7 +24,11 @@ using the Cordova / Phonegap command line interface. ## Usage -### AngularJS +### Without AngularJS + +This plugin registers a `cordovaHTTP` global on window + +### With AngularJS This plugin creates a cordovaHTTP service inside of a cordovaHTTP module. You must load the module when you create your app's module. @@ -31,12 +36,8 @@ This plugin creates a cordovaHTTP service inside of a cordovaHTTP module. You m You can then inject the cordovaHTTP service into your controllers. The functions can then be used identically to the examples shown below except that instead of accepting success and failure callback functions, each function returns a promise. For more information on promises in AngularJS read the [AngularJS docs](http://docs.angularjs.org/api/ng/service/$q). For more info on promises in general check out this article on [html5rocks](http://www.html5rocks.com/en/tutorials/es6/promises/). Make sure that you load cordova.js or phonegap.js after AngularJS is loaded. -### Not AngularJS -This plugin registers a `cordovaHTTP` global on window - - -## Sync Functions +## Synchronous Functions ### getBasicAuthHeader This returns an object representing a basic HTTP Authorization header of the form `{'Authorization': 'Basic base64encodedusernameandpassword'}` @@ -62,7 +63,10 @@ You can choose one of these two: * `urlencoded`: send data as url encoded content in body (content type "application/x-www-form-urlencoded") * `json`: send data as JSON encoded content in body (content type "application/json") -## Async Functions +Caution: `urlencoded` does not support serializing deep structures whereas `json` does. + + +## Asynchronous Functions These functions all take success and error callbacks as their last 2 arguments. ### enableSSLPinning @@ -157,6 +161,12 @@ Execute a GET request. Takes a URL, parameters, and headers. See the [post](#p console.error(response.error); }); +### put +Execute a PUT request. Takes a URL, data, and headers. See the [post](#post) documentation for details on what is returned on success and failure. + +### delete +Execute a DELETE request. Takes a URL, parameters, and headers. See the [post](#post) documentation for details on what is returned on success and failure. + ### uploadFile Uploads a file saved on the device. Takes a URL, parameters, headers, filePath, and the name of the parameter to pass the file along as. See the [post](#post) documentation for details on what is returned on success and failure. From 8fc4c2b9cb9e62011e7840f59c0ddb35cd4dba3a Mon Sep 17 00:00:00 2001 From: Sefa Ilkimen Date: Mon, 14 Nov 2016 15:13:26 +0100 Subject: [PATCH 5/5] minor changes for cleanup --- README.md | 2 +- plugin.xml | 8 ++++---- www/{cordovaHTTP.js => cordovaHttp.js} | 6 ++---- 3 files changed, 7 insertions(+), 9 deletions(-) rename www/{cordovaHTTP.js => cordovaHttp.js} (99%) diff --git a/README.md b/README.md index 68a67a3..2f94fe6 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ using the Cordova / Phonegap command line interface. ### Without AngularJS -This plugin registers a `cordovaHTTP` global on window +This plugin registers a global object located at `cordova.plugin.http`. ### With AngularJS diff --git a/plugin.xml b/plugin.xml index 381bcf0..411a291 100644 --- a/plugin.xml +++ b/plugin.xml @@ -4,20 +4,20 @@ id="cordova-plugin-advanced-http" version="1.3.0"> - SSL Pinning + Advanced HTTP plugin Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning - + - - + + diff --git a/www/cordovaHTTP.js b/www/cordovaHttp.js similarity index 99% rename from www/cordovaHTTP.js rename to www/cordovaHttp.js index 2800962..ac16312 100644 --- a/www/cordovaHTTP.js +++ b/www/cordovaHttp.js @@ -135,8 +135,6 @@ var http = { } }; -module.exports = http; - if (typeof angular !== 'undefined') { angular.module('cordovaHTTP', []).factory('cordovaHTTP', function ($timeout, $q) { function makePromise(fn, args, async) { @@ -214,6 +212,6 @@ if (typeof angular !== 'undefined') { }; return cordovaHTTP; }); -} else { - window.cordovaHTTP = http; } + +module.exports = http;