mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-05-31 00:00:07 +08:00
renamed plugin files to cordovaHTTP.
This commit is contained in:
+6
-6
@@ -16,20 +16,20 @@
|
||||
|
||||
<dependency id="org.apache.cordova.core.file" url="https://git-wip-us.apache.org/repos/asf/cordova-plugin-file" commit="master" />
|
||||
|
||||
<js-module src="www/httpsp.js" name="SSLPinningPlugin">
|
||||
<clobbers target="plugins.httpsp" />
|
||||
<js-module src="www/cordovaHTTP.js" name="CordovaHTTPPlugin">
|
||||
<clobbers target="plugins.cordovaHTTP" />
|
||||
</js-module>
|
||||
|
||||
<!-- ios -->
|
||||
<platform name="ios">
|
||||
<config-file target="config.xml" parent="/*">
|
||||
<feature name="HTTPSPinning">
|
||||
<param name="ios-package" value="HTTPSPinning"/>
|
||||
<feature name="CordovaHTTP">
|
||||
<param name="ios-package" value="CordovaHTTP"/>
|
||||
</feature>
|
||||
</config-file>
|
||||
|
||||
<header-file src="src/ios/HTTPSPinning.h" />
|
||||
<source-file src="src/ios/HTTPSPinning.m" />
|
||||
<header-file src="src/ios/CordovaHTTP.h" />
|
||||
<source-file src="src/ios/CordovaHTTP.m" />
|
||||
|
||||
<header-file src="src/ios/HTTPManager.h" />
|
||||
<source-file src="src/ios/HTTPManager.m" />
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#import <Cordova/CDVPlugin.h>
|
||||
#import <Cordova/CDVJSON.h>
|
||||
|
||||
@interface HTTPSPinning : CDVPlugin
|
||||
@interface CordovaHTTP : CDVPlugin
|
||||
|
||||
- (void)setAuthorizationHeaderWithUsernameAndPassword:(CDVInvokedUrlCommand*)command;
|
||||
- (void)setHeader:(CDVInvokedUrlCommand*)command;
|
||||
@@ -1,9 +1,9 @@
|
||||
#import "HTTPSPinning.h"
|
||||
#import "CordovaHTTP.h"
|
||||
#import "CDVFile.h"
|
||||
#import "TextResponseSerializer.h"
|
||||
#import "HTTPManager.h"
|
||||
|
||||
@implementation HTTPSPinning
|
||||
@implementation CordovaHTTP
|
||||
|
||||
- (void) setAuthorizationHeaderWithUsernameAndPassword:(CDVInvokedUrlCommand*)command {
|
||||
NSString *username = [command.arguments objectAtIndex:0];
|
||||
@@ -92,7 +92,7 @@
|
||||
NSString *url = [command.arguments objectAtIndex:0];
|
||||
NSDictionary *parameters = [command.arguments objectAtIndex:1];
|
||||
|
||||
HTTPSPinning* __weak weakSelf = self;
|
||||
CordovaHTTP* __weak weakSelf = self;
|
||||
|
||||
[manager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
@@ -100,14 +100,12 @@
|
||||
[dictionary setObject:responseObject forKey:@"data"];
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
NSLog(@"Response: %@", responseObject);
|
||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
[dictionary setObject:[NSNumber numberWithInt:operation.response.statusCode] forKey:@"status"];
|
||||
[dictionary setObject:[error localizedDescription] forKey:@"error"];
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
NSLog(@"Error: %@", error);
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -116,7 +114,7 @@
|
||||
NSString *url = [command.arguments objectAtIndex:0];
|
||||
NSDictionary *parameters = [command.arguments objectAtIndex:1];
|
||||
|
||||
HTTPSPinning* __weak weakSelf = self;
|
||||
CordovaHTTP* __weak weakSelf = self;
|
||||
|
||||
[manager GET:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
@@ -124,14 +122,12 @@
|
||||
[dictionary setObject:responseObject forKey:@"data"];
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
NSLog(@"Response: %@", responseObject);
|
||||
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
[dictionary setObject:[NSNumber numberWithInt:operation.response.statusCode] forKey:@"status"];
|
||||
[dictionary setObject:[error localizedDescription] forKey:@"error"];
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
NSLog(@"Error: %@", error);
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -144,9 +140,7 @@
|
||||
|
||||
NSURL *fileURL = [NSURL fileURLWithPath: filePath];
|
||||
|
||||
NSLog(@"%@", fileURL);
|
||||
|
||||
HTTPSPinning* __weak weakSelf = self;
|
||||
CordovaHTTP* __weak weakSelf = self;
|
||||
[manager POST:url parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
|
||||
NSError *error;
|
||||
[formData appendPartWithFileURL:fileURL name:name error:&error];
|
||||
@@ -169,7 +163,6 @@
|
||||
[dictionary setObject:[error localizedDescription] forKey:@"error"];
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
NSLog(@"Error: %@", error);
|
||||
}];
|
||||
}
|
||||
|
||||
@@ -180,7 +173,7 @@
|
||||
NSDictionary *parameters = [command.arguments objectAtIndex:1];
|
||||
NSString *filePath = [command.arguments objectAtIndex: 2];
|
||||
|
||||
HTTPSPinning* __weak weakSelf = self;
|
||||
CordovaHTTP* __weak weakSelf = self;
|
||||
[manager GET:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
|
||||
/*
|
||||
*
|
||||
@@ -243,7 +236,6 @@
|
||||
[dictionary setObject:[error localizedDescription] forKey:@"error"];
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
NSLog(@"Error: %@", error);
|
||||
}];
|
||||
}
|
||||
|
||||
Vendored
+159
@@ -0,0 +1,159 @@
|
||||
/*global angular*/
|
||||
|
||||
/*
|
||||
* An HTTP Plugin for PhoneGap.
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
|
||||
var http = {
|
||||
SSLPinningMode: {
|
||||
None: 0,
|
||||
Certificate: 1,
|
||||
PublicKey: 2
|
||||
},
|
||||
setAuthorizationHeaderWithUsernameAndPassword: function(username, password, success, failure) {
|
||||
return exec(success, failure, "CordovaHTTP", "setAuthorizationHeaderWithUsernameAndPassword", [username, password]);
|
||||
},
|
||||
setHeader: function(header, value, success, failure) {
|
||||
return exec(success, failure, "CordovaHTTP", "setHeader", [header, value]);
|
||||
},
|
||||
setSSLPinningMode: function(mode, success, failure) {
|
||||
return exec(success, failure, "CordovaHTTP", "setSSLPinningMode", [mode]);
|
||||
},
|
||||
validateEntireCertificateChain: function(validateChain, success, failure) {
|
||||
return exec(success, failure, "CordovaHTTP", "validateEntireCertificateChain", [validateChain]);
|
||||
},
|
||||
allowInvalidCertificates: function(allow, success, failure) {
|
||||
return exec(success, failure, "CordovaHTTP", "allowInvalidCertificates", [allow]);
|
||||
},
|
||||
acceptText: function(success, failure) {
|
||||
return exec(success, failure, "CordovaHTTP", "acceptText", []);
|
||||
},
|
||||
acceptData: function(success, failure) {
|
||||
return exec(success, failure, "CordovaHTTP", "acceptData", []);
|
||||
},
|
||||
setAcceptableContentTypes: function(contentTypes, success, failure) {
|
||||
return exec(success, failure, "CordovaHTTP", "setAcceptableContentTypes", contentTypes);
|
||||
},
|
||||
post: function(url, params, success, failure) {
|
||||
return exec(success, failure, "CordovaHTTP", "post", [url, params]);
|
||||
},
|
||||
get: function(url, params, success, failure) {
|
||||
return exec(success, failure, "CordovaHTTP", "get", [url, params]);
|
||||
},
|
||||
uploadFile: function(url, params, filePath, name, success, failure) {
|
||||
return exec(success, failure, "CordovaHTTP", "uploadFile", [url, params, filePath, name]);
|
||||
},
|
||||
downloadFile: function(url, params, 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
|
||||
*
|
||||
*/
|
||||
var win = function(result) {
|
||||
var entry = new (require('org.apache.cordova.core.file.FileEntry'))();
|
||||
entry.isDirectory = false;
|
||||
entry.isFile = true;
|
||||
entry.name = result.file.name;
|
||||
entry.fullPath = result.file.fullPath;
|
||||
success(entry);
|
||||
};
|
||||
return exec(win, failure, "CordovaHTTP", "downloadFile", [url, params, filePath]);
|
||||
}
|
||||
};
|
||||
|
||||
if (angular) {
|
||||
angular.module('cordovaHTTP', []).factory('cordovaHTTP', function($timeout, $q) {
|
||||
function makePromise(fn, args, async) {
|
||||
var deferred = $q.defer();
|
||||
|
||||
var success = function(response) {
|
||||
if (async) {
|
||||
$timeout(function() {
|
||||
deferred.resolve(response);
|
||||
});
|
||||
} else {
|
||||
deferred.resolve(response);
|
||||
}
|
||||
};
|
||||
|
||||
var fail = function(response) {
|
||||
if (async) {
|
||||
$timeout(function() {
|
||||
deferred.reject(response);
|
||||
});
|
||||
} else {
|
||||
deferred.reject(response);
|
||||
}
|
||||
};
|
||||
|
||||
args.push(success);
|
||||
args.push(fail);
|
||||
|
||||
fn.apply(http, args);
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
var cordovaHTTP = {
|
||||
SSLPinningMode: http.SSLPinningMode,
|
||||
setAuthorizationHeaderWithUsernameAndPassword: function(username, password) {
|
||||
return makePromise(http.setAuthorizationHeaderWithUsernameAndPassword, [username, password]);
|
||||
},
|
||||
setHeader: function(header, value) {
|
||||
return makePromise(http.setHeader, [header, value]);
|
||||
},
|
||||
setSSLPinningMode: function(mode) {
|
||||
return makePromise(http.setSSLPinningMode, [mode]);
|
||||
},
|
||||
validateEntireCertificateChain: function(validateChain) {
|
||||
return makePromise(http.validateEntireCertificateChain, [validateChain]);
|
||||
},
|
||||
allowInvalidCertificates: function(allow) {
|
||||
return makePromise(http.allowInvalidCertificates, [allow]);
|
||||
},
|
||||
acceptText: function() {
|
||||
return makePromise(http.acceptText, []);
|
||||
},
|
||||
acceptData: function() {
|
||||
return makePromise(http.acceptData, []);
|
||||
},
|
||||
setAcceptableContentTypes: function(contentTypes) {
|
||||
return makePromise(http.setAcceptableContentTypes, [contentTypes]);
|
||||
},
|
||||
post: function(url, params) {
|
||||
return makePromise(http.post, [url, params], true);
|
||||
},
|
||||
get: function(url, params) {
|
||||
return makePromise(http.get, [url, params], true);
|
||||
},
|
||||
uploadFile: function(url, params, filePath, name) {
|
||||
return makePromise(http.uploadFile, [url, params, filePath, name], true);
|
||||
},
|
||||
downloadFile: function(url, params, filePath) {
|
||||
return makePromise(http.downloadFile, [url, params, filePath], true);
|
||||
}
|
||||
};
|
||||
return cordovaHTTP;
|
||||
});
|
||||
} else {
|
||||
window.cordovaHTTP = http;
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* An HTTP Plugin for PhoneGap.
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
|
||||
var http = {
|
||||
SSLPinningMode: {
|
||||
None: 0,
|
||||
Certificate: 1,
|
||||
PublicKey: 2
|
||||
},
|
||||
setAuthorizationHeaderWithUsernameAndPassword: function(username, password, success, failure) {
|
||||
return exec(success, failure, "HTTPSPinning", "setAuthorizationHeaderWithUsernameAndPassword", [username, password]);
|
||||
},
|
||||
setHeader: function(header, value, success, failure) {
|
||||
return exec(success, failure, "HTTPSPinning", "setHeader", [header, value]);
|
||||
},
|
||||
setSSLPinningMode: function(mode, success, failure) {
|
||||
return exec(success, failure, "HTTPSPinning", "setSSLPinningMode", [mode]);
|
||||
},
|
||||
validateEntireCertificateChain: function(validateChain, success, failure) {
|
||||
return exec(success, failure, "HTTPSPinning", "validateEntireCertificateChain", [validateChain]);
|
||||
},
|
||||
allowInvalidCertificates: function(allow, success, failure) {
|
||||
return exec(success, failure, "HTTPSPinning", "allowInvalidCertificates", [allow]);
|
||||
},
|
||||
acceptText: function(success, failure) {
|
||||
return exec(success, failure, "HTTPSPinning", "acceptText", []);
|
||||
},
|
||||
acceptData: function(contentTypes, success, failure) {
|
||||
return exec(success, failure, "HTTPSPinning", "acceptData", []);
|
||||
},
|
||||
setAcceptableContentTypes: function(contentTypes, success, failure) {
|
||||
return exec(success, failure, "HTTPSPinning", "setAcceptableContentTypes", contentTypes);
|
||||
},
|
||||
post: function(url, params, success, failure) {
|
||||
return exec(success, failure, "HTTPSPinning", "post", [url, params]);
|
||||
},
|
||||
get: function(url, params, success, failure) {
|
||||
return exec(success, failure, "HTTPSPinning", "get", [url, params]);
|
||||
},
|
||||
uploadFile: function(url, params, filePath, name, success, failure) {
|
||||
return exec(success, failure, "HTTPSPinning", "uploadFile", [url, params, filePath, name]);
|
||||
},
|
||||
downloadFile: function(url, params, 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
|
||||
*
|
||||
*/
|
||||
var win = function(result) {
|
||||
var entry = new (require('org.apache.cordova.core.file.FileEntry'))();
|
||||
entry.isDirectory = false;
|
||||
entry.isFile = true;
|
||||
console.log(result);
|
||||
console.log(JSON.stringify(result));
|
||||
entry.name = result.file.name;
|
||||
entry.fullPath = result.file.fullPath;
|
||||
success(entry);
|
||||
};
|
||||
return exec(win, failure, "HTTPSPinning", "downloadFile", [url, params, filePath]);
|
||||
}
|
||||
};
|
||||
|
||||
window.http = http;
|
||||
Reference in New Issue
Block a user