mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-05-31 00:00:07 +08:00
defined www interface for configurable parameter serializer
This commit is contained in:
+7
-1
@@ -1,5 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
## v1.3.0
|
||||
|
||||
- forked from "cordova-plugin-http" v1.2.0 (see https://github.com/wymsee/cordova-HTTP)
|
||||
|
||||
# Previous changelog (cordova-plugin-http)
|
||||
|
||||
## v1.2.0
|
||||
|
||||
- Added support for TLSv1.1 and TLSv1.2 for android versions 4.1-4.4 (API levels 16-19)
|
||||
@@ -72,4 +78,4 @@
|
||||
- Reports SSL Handshake errors rather than giving a generic error (Thanks to devgeeks)
|
||||
- Exporting http as a module (Thanks to pvsaikrishna)
|
||||
- Added Limitations section to readme (Thanks to cvillerm)
|
||||
- Fixed examples (Thanks to hideov)
|
||||
- Fixed examples (Thanks to hideov)
|
||||
|
||||
+4
-4
@@ -1,9 +1,9 @@
|
||||
{
|
||||
"name": "cordova-plugin-http",
|
||||
"version": "1.2.0",
|
||||
"name": "cordova-plugin-advanced-http",
|
||||
"version": "1.3.0",
|
||||
"description": "Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning",
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-http",
|
||||
"id": "cordova-plugin-advanced-http",
|
||||
"platforms": [
|
||||
"ios",
|
||||
"android"
|
||||
@@ -11,7 +11,7 @@
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/wymsee/cordova-HTTP.git"
|
||||
"url": "git+https://github.com/silkimen/cordova-plugin-advanced-http.git"
|
||||
},
|
||||
"keywords": [
|
||||
"cordova",
|
||||
|
||||
+6
-6
@@ -1,14 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
id="cordova-plugin-http"
|
||||
version="1.2.0">
|
||||
id="cordova-plugin-advanced-http"
|
||||
version="1.3.0">
|
||||
|
||||
<name>SSL Pinning</name>
|
||||
|
||||
|
||||
<description>
|
||||
Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning
|
||||
</description>
|
||||
</description>
|
||||
|
||||
<engines>
|
||||
<engine name="cordova" version=">=3.0.0" />
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
<header-file src="src/ios/CordovaHttpPlugin.h" />
|
||||
<source-file src="src/ios/CordovaHttpPlugin.m" />
|
||||
|
||||
|
||||
<header-file src="src/ios/TextResponseSerializer.h" />
|
||||
<source-file src="src/ios/TextResponseSerializer.m" />
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
<config-file target="AndroidManifest.xml" parent="/manifest">
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
</config-file>
|
||||
|
||||
|
||||
<source-file src="src/android/com/synconset/CordovaHTTP/CordovaHttp.java" target-dir="src/com/synconset" />
|
||||
<source-file src="src/android/com/synconset/CordovaHTTP/CordovaHttpGet.java" target-dir="src/com/synconset" />
|
||||
<source-file src="src/android/com/synconset/CordovaHTTP/CordovaHttpPost.java" target-dir="src/com/synconset" />
|
||||
|
||||
Vendored
+91
-65
@@ -1,14 +1,40 @@
|
||||
/*global angular*/
|
||||
|
||||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Modified by Andrew Stephan for Sync OnSet
|
||||
* Modified by Sefa Ilkimen:
|
||||
* - added configurable params serializer
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* An HTTP Plugin for PhoneGap.
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var validSerializers = ['urlencoded', 'json'];
|
||||
|
||||
// Thanks Mozilla: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_.22Unicode_Problem.22
|
||||
function b64EncodeUnicode(str) {
|
||||
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
|
||||
return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
|
||||
return String.fromCharCode('0x' + p1);
|
||||
}));
|
||||
}
|
||||
@@ -25,68 +51,65 @@ function mergeHeaders(globalHeaders, localHeaders) {
|
||||
return localHeaders;
|
||||
}
|
||||
|
||||
function checkSerializer(serializer) {
|
||||
serializer = serializer || '';
|
||||
serializer = serializer.trim().toLowerCase();
|
||||
|
||||
if (validSerializers.indexOf(serializer) > -1) {
|
||||
return serializer;
|
||||
}
|
||||
|
||||
return serializer[0];
|
||||
}
|
||||
|
||||
var http = {
|
||||
headers: {},
|
||||
paramSerializer: 'urlencoded',
|
||||
sslPinning: false,
|
||||
getBasicAuthHeader: function(username, password) {
|
||||
getBasicAuthHeader: function (username, password) {
|
||||
return {'Authorization': 'Basic ' + b64EncodeUnicode(username + ':' + password)};
|
||||
},
|
||||
useBasicAuth: function(username, password) {
|
||||
useBasicAuth: function (username, password) {
|
||||
this.headers.Authorization = 'Basic ' + b64EncodeUnicode(username + ':' + password);
|
||||
},
|
||||
setHeader: function(header, value) {
|
||||
setHeader: function (header, value) {
|
||||
this.headers[header] = value;
|
||||
},
|
||||
enableSSLPinning: function(enable, success, failure) {
|
||||
return exec(success, failure, "CordovaHttpPlugin", "enableSSLPinning", [enable]);
|
||||
setParamSerializer: function (serializer) {
|
||||
this.paramSerializer = checkSerializer(serializer);
|
||||
},
|
||||
acceptAllCerts: function(allow, success, failure) {
|
||||
return exec(success, failure, "CordovaHttpPlugin", "acceptAllCerts", [allow]);
|
||||
enableSSLPinning: function (enable, success, failure) {
|
||||
return exec(success, failure, 'CordovaHttpPlugin', 'enableSSLPinning', [enable]);
|
||||
},
|
||||
validateDomainName: function(validate, success, failure) {
|
||||
return exec(success, failure, "CordovaHttpPlugin", "validateDomainName", [validate]);
|
||||
acceptAllCerts: function (allow, success, failure) {
|
||||
return exec(success, failure, 'CordovaHttpPlugin', 'acceptAllCerts', [allow]);
|
||||
},
|
||||
post: function(url, params, headers, success, failure) {
|
||||
validateDomainName: function (validate, success, failure) {
|
||||
return exec(success, failure, 'CordovaHttpPlugin', 'validateDomainName', [validate]);
|
||||
},
|
||||
post: function (url, params, headers, success, failure) {
|
||||
params = params || {};
|
||||
headers = headers || {};
|
||||
headers = mergeHeaders(this.headers, headers);
|
||||
return exec(success, failure, "CordovaHttpPlugin", "post", [url, params, headers]);
|
||||
return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, params, this.serializer, headers]);
|
||||
},
|
||||
get: function(url, params, headers, success, failure) {
|
||||
get: function (url, params, headers, success, failure) {
|
||||
params = params || {};
|
||||
headers = headers || {};
|
||||
headers = mergeHeaders(this.headers, headers);
|
||||
return exec(success, failure, "CordovaHttpPlugin", "get", [url, params, headers]);
|
||||
return exec(success, failure, 'CordovaHttpPlugin', 'get', [url, params, headers]);
|
||||
},
|
||||
head: function(url, params, headers, success, failure) {
|
||||
head: function (url, params, headers, success, failure) {
|
||||
headers = mergeHeaders(this.headers, headers);
|
||||
return exec(success, failure, "CordovaHttpPlugin", "head", [url, params, headers]);
|
||||
return exec(success, failure, 'CordovaHttpPlugin', 'head', [url, params, headers]);
|
||||
},
|
||||
uploadFile: function(url, params, headers, filePath, name, success, failure) {
|
||||
uploadFile: function (url, params, headers, filePath, name, success, failure) {
|
||||
headers = mergeHeaders(this.headers, headers);
|
||||
return exec(success, failure, "CordovaHttpPlugin", "uploadFile", [url, params, headers, filePath, name]);
|
||||
return exec(success, failure, 'CordovaHttpPlugin', 'uploadFile', [url, params, headers, filePath, name]);
|
||||
},
|
||||
downloadFile: function(url, params, headers, filePath, success, failure) {
|
||||
/*
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
* Modified by Andrew Stephan for Sync OnSet
|
||||
*
|
||||
*/
|
||||
downloadFile: function (url, params, headers, filePath, success, failure) {
|
||||
headers = mergeHeaders(this.headers, headers);
|
||||
var win = function(result) {
|
||||
var win = function (result) {
|
||||
var entry = new (require('cordova-plugin-file.FileEntry'))();
|
||||
entry.isDirectory = false;
|
||||
entry.isFile = true;
|
||||
@@ -96,75 +119,78 @@ var http = {
|
||||
entry.nativeURL = result.file.nativeURL;
|
||||
success(entry);
|
||||
};
|
||||
return exec(win, failure, "CordovaHttpPlugin", "downloadFile", [url, params, headers, filePath]);
|
||||
return exec(win, failure, 'CordovaHttpPlugin', 'downloadFile', [url, params, headers, filePath]);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = http;
|
||||
|
||||
if (typeof angular !== "undefined") {
|
||||
angular.module('cordovaHTTP', []).factory('cordovaHTTP', function($timeout, $q) {
|
||||
if (typeof angular !== 'undefined') {
|
||||
angular.module('cordovaHTTP', []).factory('cordovaHTTP', function ($timeout, $q) {
|
||||
function makePromise(fn, args, async) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
var success = function(response) {
|
||||
|
||||
var success = function (response) {
|
||||
if (async) {
|
||||
$timeout(function() {
|
||||
$timeout(function () {
|
||||
deferred.resolve(response);
|
||||
});
|
||||
} else {
|
||||
deferred.resolve(response);
|
||||
}
|
||||
};
|
||||
|
||||
var fail = function(response) {
|
||||
|
||||
var fail = function (response) {
|
||||
if (async) {
|
||||
$timeout(function() {
|
||||
$timeout(function () {
|
||||
deferred.reject(response);
|
||||
});
|
||||
} else {
|
||||
deferred.reject(response);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
args.push(success);
|
||||
args.push(fail);
|
||||
|
||||
|
||||
fn.apply(http, args);
|
||||
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
||||
var cordovaHTTP = {
|
||||
getBasicAuthHeader: http.getBasicAuthHeader,
|
||||
useBasicAuth: function(username, password) {
|
||||
useBasicAuth: function (username, password) {
|
||||
return http.useBasicAuth(username, password);
|
||||
},
|
||||
setHeader: function(header, value) {
|
||||
setHeader: function (header, value) {
|
||||
return http.setHeader(header, value);
|
||||
},
|
||||
enableSSLPinning: function(enable) {
|
||||
setParamSerializer: function (serializer) {
|
||||
return http.setParamSerializer(serializer);
|
||||
},
|
||||
enableSSLPinning: function (enable) {
|
||||
return makePromise(http.enableSSLPinning, [enable]);
|
||||
},
|
||||
acceptAllCerts: function(allow) {
|
||||
acceptAllCerts: function (allow) {
|
||||
return makePromise(http.acceptAllCerts, [allow]);
|
||||
},
|
||||
validateDomainName: function(validate) {
|
||||
validateDomainName: function (validate) {
|
||||
return makePromise(http.validateDomainName, [validate]);
|
||||
},
|
||||
post: function(url, params, headers) {
|
||||
post: function (url, params, headers) {
|
||||
return makePromise(http.post, [url, params, headers], true);
|
||||
},
|
||||
get: function(url, params, headers) {
|
||||
get: function (url, params, headers) {
|
||||
return makePromise(http.get, [url, params, headers], true);
|
||||
},
|
||||
head: function(url, params, headers) {
|
||||
head: function (url, params, headers) {
|
||||
return makePromise(http.head, [url, params, headers], true);
|
||||
},
|
||||
uploadFile: function(url, params, headers, filePath, name) {
|
||||
uploadFile: function (url, params, headers, filePath, name) {
|
||||
return makePromise(http.uploadFile, [url, params, headers, filePath, name], true);
|
||||
},
|
||||
downloadFile: function(url, params, headers, filePath) {
|
||||
downloadFile: function (url, params, headers, filePath) {
|
||||
return makePromise(http.downloadFile, [url, params, headers, filePath], true);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
{
|
||||
"preferences": {
|
||||
"tabSize": 2,
|
||||
"wordWrap": true,
|
||||
"useSoftTabs": true,
|
||||
"gotoExclude": []
|
||||
},
|
||||
"packages": [
|
||||
"gh:wymsee/zed-tools/mobile"
|
||||
],
|
||||
"modes": {
|
||||
"javascript": {
|
||||
"commands": {
|
||||
"Tools:Check": {
|
||||
"options": {
|
||||
"globals": {
|
||||
"angular": true,
|
||||
"$": true,
|
||||
"device": true,
|
||||
"persistence": true,
|
||||
"moment": true,
|
||||
"sos": true,
|
||||
"LocalFileSystem": true,
|
||||
"Hammer": true,
|
||||
"AnimationFrame": true,
|
||||
"Bloodhound": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user